Skip to content
go-rule engine
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
testdata
README.MD
ast.go
ast_test.go
composite_rule.go
context.go
context_test.go
env.go
env_test.go
errors.go
eval.go
eval_test.go
parse.go
parse_test.go
token.go
token_test.go
unit_rule.go
unit_rule_test.go

README.MD

GO Rule engine support only number type

example

package main

import (
	"fmt"

	rule "github.com/Salpadding/go-rule"
)

func main() {
	evaultor := rule.NewEvaluator()
	// let assign variable rs1rule1 a rule
	evaultor.Eval(`(export rs1rule1 'c0 <= -9')`)
	// (or rule1 rule2) return composite rule
	evaultor.Eval(`(let rs1rule1 
			(or rs1rule1 (atLeast 2 'c0>=8' 'c1>=8' 'c2>=8' 'c3>=8' 'c4>=8' 'c5>=8' 'c6>=8' 'c7>=8'))
		)`)
	// (atLeast 2 rule1 rule2 rule3) success when at least 2 of rule1 rule2 success
	evaultor.Eval(`(let rs1rule1
			(or rs1rule1 
				(atLeast 2 'c0<=-8' 'c1<=-8' 'c2<=-8' 'c3<=-8' 'c4<=-8' 'c5<=-8' 'c6<=-8' 'c7<=-8')
			)
		)`)
	evaultor.Eval(`(
		let rs1rule1 (and rs1rule1 'isSportOrDrunk=1' )
	)`)
	ctx := rule.NewContext(map[string]interface{}{
		"c0":             10,
		"c1":             0,
		"c2":             0,
		"c3":             0,
		"c4":             0,
		"c5":             0,
		"c6":             0,
		"c7":             0,
		"isSportOrDrunk": 1,
	})
	results := evaultor.Expect(ctx)
	fmt.Printf("%v", results["rs1rule1"].Ok)
}
You can’t perform that action at this time.