this is a rule engine named Gengine based on golang and AST, it can help you to load your code(rules) to run while you did not need to restart your application.
Gengine's code structure is Modular design, logic is easy to understand, and it passed the necessary testing!
support the priority of the rules list and the priority scope is -int64 to int64
support rule's description
support define a local variable in a rule, and it invisible between rules
support 'if..else ../ if ..else... /if .. else if ... else' and it's Nested structure
support complex logic operation
support complex Arithmetic (+ - * /)
support method of golang's structure
support single line comment(//)
support elegant check error, if there is an error in one rule, gengine will not load the rules to run to forbidden the harm to data
to make it easy to use,Gengine just supports one return value function's or method's Assignment and support return struct, but support call multi return value function
support directly inject function to run, and rename function
support switch to help user to decide when a rule execute error in the list whether continue to execute the last rules
support use '@name' to get rule's name in rule content
support map, slice, array
support rule pool, code location: gengine/engine/gengine_pool.go, test case: gengine/test/Pool_test.go
Gengine not support grammar
not support Multi-level call such as 'user.ip.ipRisk()',because it not meet the "Dimit rule", and multi-level call make it hard to understand, so it just support this call type: 'ip.ipRisk()'
not support multi line comment (/* comment */)
not support multi return value, if you want, you can use return struct
not support nil
something need your attention
if you not declare the rules' priority, the rules will be execute in unknown sort
every rule's name should be different from each other
support data type
string
bool
int, int8, int16, int32, int64
float32, float64
support logic operation
&&
||
!
support compared operation
==
!=
>
<
>=
<=
support math operation
+
-
*
/
support string and string's plus
attention and in action
if you want get high performance, please do as the test case do: separate the rule build process and the rule execute process
when you rules contains Very time-consuming operation, such as operate database, you should use engine.ExecuteConcurrent(...), if not ,you should still use engine.Execute(...)
newest version is compatible with all older versions
use
go mod or go vendor
Gengine rule example
//rulerule"测试""测试描述"salience0begin// rename function test; @name represent the rule name "测试"Sout(@name)
// common function testHello()
//struct's method testUser.Say()
// ifif!(7==User.GetNum(7)) ||!(7>8) {
//define variable and string's plus; @name is just a stringvariable="hello"+ (" world"+"zeze")+"@name"// inner functionUser.Name="hhh"+strconv.FormatBool(true)
//struct's field User.Age=User.GetNum(8976) /1000+3*(1+1)
//bool set testUser.Male=false//use inner variable testUser.Print(variable)
//float test f=9.56PrintReal(f)
//if-else testiffalse {
Sout("sout true")
}else{
Sout("sout false")
}
}else{ //else//struct field set value testUser.Name="yyyy"
}
end