• Stars
    star
    11
  • Rank 1,694,829 (Top 34 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 5 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a rule-engine with custom dsl for golang

Example:

 func now() int64 { return time.Now().Unix() }
 func days(count float64) float64 {
 	return count * 24 * 60 * 60
 }

 func main() {
 	funcMap := map[string]interface{}{
		"now":  now,
		"days": days,
	}
	inputMap := map[string]interface{}{
		"registered_date": time.Now().Unix(),
		"sales_amount":    2000000,
	}
	outputMap := map[string]interface{}{
		"plan_name": "premium_1",
	}
	output, err := mosalat.Run([]string{
		`now() > registered_date + days(14) && plan_name == "premium_1" | plan_name = "free"`,
		`plan_name == "premium_1" | plan_name = "free"`,
		`plan_name == "free" | feature_1 = true`,
	}, funcMap, inputMap, outputMap) // --> [plan_name: "free", feature_1: true]
 }