- this repo has been moved to bilibili/gengine(https://github.com/bilibili/gengine)
- it open source still based on BSD
- 简体中文 使用交流Q群1132683357(群内有官方交流微信群二维码,解答所有的gengine问题)
Rule Engine for Golang
License: Other
go mod =>
module test
go 1.15
require(
gengine v1.0.8
)
replace gengine => github.com/rencalo770/gengine v1.1.5
Do you have some benchmarks with other projects in the industry?
Such as gopherlua, tengo, goja, etc.
We need the support of building rules from JSON
I am trying to figure out how to adjust the parameter configuration to improve performance, but I am not sure about the relationship between these parameters and the server configuration, and how they affect performance, please give me some suggestions, thanks.
type MapTypeWithKeyStr map[string]int
type MapTypeWithKeyInt map[int]string
//define
type MS struct {
MII *map[int]int
MSI MapTypeWithKeyStr
MIS MapTypeWithKeyInt
}
//init
MS := &MS{
MII: &map[int]int{1: 1},
MSI: MapTypeWithKeyStr{"hello": 1},
MIS: MapTypeWithKeyInt {1: "hello"},
}
map[string]int 的情况下。。无法做运算吗?intMap["test"]= 1 可以执行,intMap["test"]= 1+1 执行报错:reflect: call of reflect.Value.Int on float64 Value、可并不是 float64啊
Just use the go mod configuration:
`module ruleengine
require gengine v1.4.7
replace gengine => github.com/rencalo770/gengine v1.4.7
go 1.15`
when running command: go mod verify, there always come the error:
gengine v1.4.7: missing ziphash: open hash: no such file or directory
Any advice on fixing the error?
您好!
首先非常感觉您提供一个很好的开源项目。我在使用时遇到这个的问题,我感觉是一个Bug但不确定。
以下是我的测试脚本:
rule "test01" "test" begin
a =1.0 x=0.0
b = req.GetArgs(@name,0)
x = a + b + 2000
end
参数InArgs是在初始化req结构时定义好的,通过注入的req结构方法来获得每个规则执行时的输入参数。
//Request . 规则请求结构
type Request struct {
//当前账户系统信息
pubstruct.AccountInfo
// 规则执行设置 [规则名][参数1~n]
InArgs map[string][]interface{}
}
func (me *Request) GetArgs(ruleName string, idx int) interface{} {
if v, ok := me.InArgs[ruleName]; ok {
return v[idx]
}
return nil
}
规则在执行到math.go 第49行时报错,程序终止,原因是因为req.GetArgs 返回的是一个interface{} 【实际是float64】
if strings.HasPrefix(bkind, "int") { // 这里会放行所有int,interface也会放行 我在测试时 bkind刚好是interface
return a.Float() + float64(b.Int()), nil //math.go:49
}
我已修正了GetArgs的返回类型,目前运行正常。以上报告供您参考。
再次感谢
浙江嘉兴 老李
B 站新一代 golang 规则引擎的设计与实现
这个文章是否撤掉?
是的,有没有地方可以看到。
ps:此为建议,非BUG反馈。
对于一个新出来的东西,可能有一些人特别是像我们这种刚开始接触用的人,
一看一脸懵逼,不知道咋用。
建议增加一个使用案例,各种方式实践的,这对于入门使用感觉还是很重要的。
当然这是在你们实践允许的情况下弄。
往往好的例子,让新手入门简单可能对拓广面比较有帮助吧。
同时,可否建立个交流群,一起讨论使用啥的也好
谢谢
why UpdatePooledRulesIncremental do not support update apis attr, always need to update api attr while update rules
engine/gengine.go ExecuteConcurrent函数 r变量闭包了,应该用rr
eMsg = append(eMsg, fmt.Sprintf("rule: \"%s\" executed, error:\n %+v ", r.RuleName, e))
其他几个模式,带有并发的都有这个bug,可以修改下~
Hello, I read the example:
...
type User struct {
Name string
Age int64
Male bool
}
func (u *User)GetNum(i int64) int64 {
return i
}
func (u *User)Print(s string){
fmt.Println(s)
}
func (u *User)Say(){
fmt.Println("hello world")
}
const (
base_rule = ...
func exe(user *User){
dataContext := context.NewDataContext()
//inject struct
dataContext.Add("User", user)
...
//init rule engine
knowledgeContext := base.NewKnowledgeContext()
ruleBuilder := builder.NewRuleBuilder(knowledgeContext, dataContext)
//读取规则
start1 := time.Now().UnixNano()
err := ruleBuilder.BuildRuleFromString(base_rule)
end1 := time.Now().UnixNano()
logrus.Infof("rules num:%d, load rules cost time:%d ns", len(knowledgeContext.RuleEntities), end1-start1 )
if err != nil{
logrus.Errorf("err:%s ", err)
}else{
eng := engine.NewGengine()
start := time.Now().UnixNano()
// true: means when there are many rules, if one rule execute error,continue to execute rules after the occur error rule
err := eng.Execute(ruleBuilder, true)
...
}
}
func Test_Base(t *testing.T){
user := &User{
Name: "Calo",
Age: 0,
Male: true,
}
exe(user) // HERE: If I have a list of user, for example I have 10 user object, how to run exe(user) efficiently?
}
My questions is: if I have a list of user, with 10 user objects. How to run exe(user) 10 times but more efficiently.
Because in the exe it will execute the functions in sequence as below:
NewDataContext, then NewKnowledgeContext, NewRuleBuilder, NewGengine and eng.Execute(ruleBuilder, true). I think those methods are just duplicated running for 10 times, how can I inject each of the user object in the list by the function dataContext.Add("User",user), but do not execute other function each time I inject a new user object?
环境
golang go 1.14.1
GOPROXY=https://goproxy.cn
GOSUMDB=off
操作系统:windown 10.0.18363 暂缺 Build 18363
I meet a problem to use "conc{}" to run rules, when there is panic happens for some reason, web service main thread will crash and service stop. seem like it wouldn't happen in non-concurrent.
how can i recover the service?
I try to compose rule like this
rule "whitelist" "use in white list pass" salience 10
BEGIN
if InWhitelist(userNo) {
// pass
} else {
// continue
}
END
rule "blacklist" "use in black list deny" salience 5
BEGIN
if InBlacklist(User.UserNo) {
// deny
}
END
...
how can i use ExecuteWithStopTag achieve stop run rest rule if user in whitelist?
You may need to make a BSD licence file for your framework "gengine" to make everyone use it without worry. not only just a BSD label.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.