bilibili / gengine

Other
1.97k stars 275 forks source link

规则语法里面是否支持for循环? #15

Open fxdgg opened 3 years ago

fxdgg commented 3 years ago

请问gengine的规则里面,不支持for循环吗?只能通过下标一个个单独去访问吗?目前来看,我们只能遍历调用了,效率可能是个问题,多谢了哈

rencalo770 commented 3 years ago

不支持

tx7do commented 2 years ago

可以支持一下,像grule这样的:

type MyPoGo struct { Name string }

func (p *MyPoGo) GetStringLength(sarg string) int { return len(sarg) }

func (p *MyPoGo) AppendString(aString, subString string) string { return fmt.Sprintf("%s%s", aString, subString) }

func TestCycleCallRule(t *testing.T) { drl := rule AgeNameCheck "test" { when Pogo.GetStringLength(Pogo.Name) < 100 then Pogo.Name = Pogo.AppendString(Pogo.Name, "Groooling"); } eng := NewRuleEngine() err := eng.Start() assert.Nil(t, err)

nodeName := "Pogo"

pogo := &model.MyPoGo{Name: "bobo"}

apis := make(rulengine.PropertiesMap)
apis["Pogo"] = pogo

err = eng.AddNode(nodeName, drl, apis)
assert.Nil(t, err)

err = eng.Execute(nodeName, true)
assert.Nil(t, err)

fmt.Println(pogo.Name)

}