Skip to content

核心API

rencalo770 edited this page Feb 9, 2021 · 3 revisions

gengine架构

  • gengine 只有四个关键api,分别是gengine的dataContext, ruleBuilder , engineGenginePool

dataContext

dataContext := context.NewDataContext()
//用户注入需要在规则代码中使用的API
dataContext.Add("println",fmt.Println)

ruleBuilder

const rule = `
rule "1" "rule-des" salience 10
begin
println("hello world, gengine!")
end
`

dataContext := context.NewDataContext()
//用户注入需要在规则代码中使用的API
dataContext.Add("println",fmt.Println)

ruleBuilder := builder.NewRuleBuilder(dataContext)
err := ruleBuilder.BuildRuleFromString(rule)

engine

const rule = `
rule "1" "rule-des" salience 10
begin
println("hello world, gengine!")
end
`

dataContext := context.NewDataContext()
//用户注入需要在规则代码中使用的API
dataContext.Add("println",fmt.Println)
	
ruleBuilder := builder.NewRuleBuilder(dataContext)
err := ruleBuilder.BuildRuleFromString(rule)
	
eng := engine.NewGengine()
err := eng.Execute(ruleBuilder, true)

GenginePool

internal

  • internal文件夹中的代码是gengine的核心,用户可以不必关心其实现