Minimalist rules engine for Golang.
package main
import (
"fmt"
"github.com/miaogaolin/condition"
)
func main() {
data := map[string]interface{}{
"col1": 1,
"col2": "hello world",
"col3": "male",
}
c, err := condition.New(`({col1}==1 and {col2} =~ "world") or {col3} in ["male"]`)
if err != nil {
panic(err)
}
res, err := c.Validate(data)
if err != nil {
panic(err)
}
if res {
fmt.Println("success")
}
}
==
>
<
>=
<=
!=
in
not in
=~ // Contains
!= // Not contained