Exemple #1
0
func main() {
	data := flag.String("data", "", "data")
	rules := flag.String("rules", "", "rules file path")
	flag.Parse()

	tks := strings.Split(*data, "&")
	obj := make(map[string]interface{})
	for _, tk := range tks {
		kv := strings.Split(tk, "=")
		obj["$"+kv[0]] = GuessType(kv[1])
	}
	fmt.Println(obj)

	ruleEngine := rulengine.NewRuleEngine()
	ruleEngine.Load(*rules)
	actions := ruleEngine.GetAction(obj)
	fmt.Println("--------------")
	for _, action := range actions {
		fmt.Println(action)
	}
}
Exemple #2
0
func main() {
	engine := rulengine.NewRuleEngine()
	engine.AddExpression("$user.age > 35", "age_larger_than_35")
	engine.AddExpression("$user.gender == male", "male")
	engine.AddExpression("$user.gender == female", "female")
	engine.AddRule(&logic.Rule{Expression: "age_larger_than_35 & male", Action: "Pass"})

	data := facts.NewFactCollection()
	user := `
		{
			"age" : 47,
			"gender" : "male"
		}
	`
	fact := facts.NewFact(user)
	data.Add("user", fact)

	exprNames := engine.GetFiredExpressions(data)
	log.Println(exprNames)

	actions := engine.GetAction(data)
	log.Println(actions)
}