miaogaolin / condition

Minimalist rules engine for Golang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minimalist rules engine for Golang.

Usage Example

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")
    }
}

Other Symbols

== 
> 
< 
>=
<=
!=
in  
not in 
=~  // Contains
!= // Not contained

About

Minimalist rules engine for Golang.

License:MIT License


Languages

Language:Go 55.8%Language:ANTLR 44.2%