Skip to content
forked from nikunjy/rules

Generic Rules engine in golang

License

Notifications You must be signed in to change notification settings

sanghinitin/rules

 
 

Repository files navigation

Golang Rules Engine Build Status codecov

Rules engine written in golang with the help of antlr.

This package will be very helpful in situations where you have a generic rule and want to verify if your values (specified using map[string]interface{}) satisfy the rule.

Here are some examples:

  type obj map[string]interface{}
  
  parser.Evaluate("x eq 1", obj{"x": 1})
  parser.Evaluate("x == 1", obj{"x": 1})
  parser.Evaluate("x lt 1", obj{"x": 1})
  parser.Evaluate("x < 1", obj{"x": 1})
  parser.Evaluate("x gt 1", obj{"x": 1})
  
  parser.Evaluate("x.a == 1 and x.b.c <= 2", obj{
    "x": obj{
       "a": 1,
       "b": obj{
          "c": 2,
       },
    },
  })
  

  parser.Evaluate("y == 4 and (x > 1)", obj{"x": 1})

  parser.Evaluate("y == 4 and (x IN [1,2,3])", obj{"x": 1})

  parser.Evaluate("y == 4 and (x eq 1.2.3)", obj{"x": "1.2.3"})
  

Operations

All the operations can be written capitalized or lowercase (ex: eq or EQ can be used)

Logical Operations supported are AND OR

Compare Expression and their definitions (a|b means you can use either one of the two a or b):

eq|==: equals to 
ne|!=: not equals to
lt|<: less than 
gt|>: greater than
le|<=: less than equal to
ge|>=: greater than equal to 
co: contains 
sw: starts with 
ew: ends with
in: in a list
pr: present
not: not of a logical expression

About

Generic Rules engine in golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 96.4%
  • ANTLR 1.9%
  • Makefile 1.7%