Skip to content

基于 golang 原生语法解析器实现的轻量级规则引擎

License

Notifications You must be signed in to change notification settings

wangxin1248/gparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gparser

基于 golang 原生语法解析器(parser)实现的轻量级规则引擎。支持操作:

  • 规则匹配:gparser.Match(ruleStr, params)

下载方式:

go get github.com/wangxin1248/gparser

使用方式:

import "github.com/wangxin1248/gparser"

ruleStr := "!(a == 1 && b == 2 && c == "test" && d == false)"

// 匹配变量
params := map[string]interface{}{
    "a": 1,
    "b": 2,
    "c": "test",
    "d": true,
}

result, err := gparser.Match(ruleStr, params)
fmt.Println(result)

支持类型

  • int
  • int64
  • string
  • bool

支持操作

  • !表达式:支持一元表达式
  • &&:支持多个表达式逻辑与
  • ||:支持多个表达式逻辑或
  • ():支持表达式括号包裹
  • ==:int、int64、string、bool支持
  • !=:int、int64、string、bool支持
  • >:int、int64支持
  • <:int、int64支持
  • >=:int、int64支持
  • <=:int、int64支持
  • +:int、int64支持
  • -:int、int64支持
  • *:int、int64支持
  • /:int、int64支持

性能对比

BenchmarkGParser_Match-8              127189          8912   ns/op     // gparser
BenchmarkGval_Match-8                 63584           18358  ns/op     // gval
BenchmarkGovaluateParser_Match-8      13628           86955  ns/op     // govaluate
BenchmarkYqlParser_Match-8            10364           112481 ns/op     // yql

About

基于 golang 原生语法解析器实现的轻量级规则引擎

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages