Skip to content

nurettintopal/rule-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rule-engine

a basic rule engine implementation in Golang

what is a rule engine?

Rules engines or rule expressions serve as pluggable software components which execute business rules that a business rules approach has externalized or separated from application code. This externalization or separation allows business users to modify the rules without the need for a big effort.

if you want to look into the details, follow this link, please.

usage

  • TBD
  • TBD

input:

{
  "country": "Turkey",
  "city": "Istanbul",
  "district": "Kadikoy",
  "population": 20000,
  "language": "Turkish"
}

rules:

{
  "conditions":[
    {
      "all":[
        {
          "field":"country",
          "operator":"equals",
          "value":"Turkey"
        },
        {
          "field":"city",
          "operator":"equals",
          "value":"Istanbul"
        },
        {
          "field":"district",
          "operator":"equals",
          "value":"Kadikoy"
        },
        {
          "field":"population",
          "operator":"equals",
          "value":20000.00
        },
        {
          "field":"population",
          "operator":"notEquals",
          "value":50000.00
        },
        {
          "field":"population",
          "operator":"lessThan",
          "value":21000.00
        },
        {
          "field":"population",
          "operator":"lessThanInclusive",
          "value":20000.00
        },
        {
          "field":"population",
          "operator":"greaterThan",
          "value":19000.00
        },
        {
          "field":"population",
          "operator":"greaterThanInclusive",
          "value":20000.00
        },
        {
          "field":"country",
          "operator":"in",
          "value":[
            "Turkey"
          ]
        },
        {
          "field":"country",
          "operator":"notIn",
          "value":[
            "Germany"
          ]
        }
      ],
      "any":[
        {
          "field":"country",
          "operator":"equals",
          "value":"England"
        },
        {
          "field":"city",
          "operator":"equals",
          "value":"London"
        },
        {
          "field":"population",
          "operator":"equals",
          "value":200000.00
        },
        {
          "field":"country",
          "operator":"equals",
          "value":"Turkey"
        },
        {
          "field":"city",
          "operator":"equals",
          "value":"Madrid"
        },
        {
          "field":"population",
          "operator":"equals",
          "value":1000.00
        }
      ]
    }
  ]
}

result:

Rules have been executed. it passed!

operators

operator meaning
equals equals to
notEquals not equal to
lessThan less than
greaterThan greater than
lessThanInclusive less than or equal to
greaterThanInclusive greater than or equal to
in in a list
notIn not in a list
startsWith starts with
endsWith ends with
contains contains
notContains not contains
regex contains any match of the regular expression pattern

dependencies

  • Go

contributing

  • if you want to add anything, contributions are welcome.
  • Open a pull request that has your explanations

license

leaderboard is open-sourced software licensed under the MIT license.