Migrated to https://github.coupang.net/coupang/couplay-fished
Fish answers from rules and facts
$ go get -u github.com/jonathansudibya/fished
or using dep
$ dep ensure -add github.com/jonathansudibya/fished
Rule :
type Rule struct {
Output string `json:"output"`
Input []string `json:"input"`
Expression string `json:"expression"`
...
}
Engine:
type Engine struct {
Facts map[string]interface{}
Rules []Rule
RuleFunctions map[string]govaluate.ExpressionFunction
Jobs chan int
...
}
Please see in test file especially TestRun()
function.
package main
import "github.com/jonathansudibya/fished"
func main() {
e := fished.New(nil)
e.SetRules([]Rule{
Rule{
Input: []string{"hello"},
Output: "result_end",
Expression: "hello == 'world'",
}
})
e.SetFacts = map[string]interface{}{
"hello": "world"
}
res, errs := e.Run()
fmt.Println(res) // will result true
}
Remember it is more expensive to set new rules than to set facts.
This project is powered by
- https://github.com/Knetic/govaluate. Please check if you need an arbitrary expression checker!
- https://github.com/json-iterator/go. One of (or the fastest) drop-in replacement for standart json library.
- https://github.com/stretchr/testify. A nice and clean testing library. Helping me a lot for better test results.
See LICENSE.md