{"id":13616079,"url":"https://github.com/nikunjy/rules","last_synced_at":"2026-01-17T03:57:51.860Z","repository":{"id":40625737,"uuid":"181827066","full_name":"nikunjy/rules","owner":"nikunjy","description":"Generic Rules engine in golang ","archived":false,"fork":false,"pushed_at":"2024-02-24T12:13:47.000Z","size":312,"stargazers_count":213,"open_issues_count":8,"forks_count":44,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-02T20:47:52.084Z","etag":null,"topics":["antlr","golang","json-query","json-rules","jsonquery","rules","rules-engine"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikunjy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-17T06:03:29.000Z","updated_at":"2024-07-29T06:25:40.000Z","dependencies_parsed_at":"2022-09-20T12:42:32.139Z","dependency_job_id":"c409aa3a-d72c-4aca-9eb5-f43cede8dc85","html_url":"https://github.com/nikunjy/rules","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikunjy%2Frules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikunjy%2Frules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikunjy%2Frules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikunjy%2Frules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikunjy","download_url":"https://codeload.github.com/nikunjy/rules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223611703,"owners_count":17173486,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antlr","golang","json-query","json-rules","jsonquery","rules","rules-engine"],"created_at":"2024-08-01T20:01:23.318Z","updated_at":"2026-01-17T03:57:51.834Z","avatar_url":"https://github.com/nikunjy.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/nikunjy/rules?style=flat-square)](https://goreportcard.com/report/github.com/nikunjy/rules)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/github.com/nikunjy/rules)](https://pkg.go.dev/github.com/nikunjy/rules)\n[![Release](https://img.shields.io/github/v/release/nikunjy/rules?sort=semver\u0026style=flat-square)](https://github.com/nikunjy/rules/releases/latest)\n[![Release](https://img.shields.io/github/go-mod/go-version/nikunjy/rules?style=flat-square)](https://github.com/nikunjy/rules/releases/latest)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=flat-square)](https://github.com/nikunjy/rules/commits)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![GitHub stars](https://img.shields.io/github/stars/nikunjy/rules?style=flat-square\u0026label=Star\u0026maxAge=2592000)](https://github.com/nikunjy/rules/stargazers/)\n\n# Golang Rules Engine\n\nRules engine written in golang with the help of antlr.\n\nThis 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.\n\nHere are some examples:\n\n```\n  parser.Evaluate(\"x eq 1\", map[string]interface{}{\"x\": 1})\n  parser.Evaluate(\"x == 1\", map[string]interface{}{\"x\": 1})\n  parser.Evaluate(\"x lt 1\", map[string]interface{}{\"x\": 1})\n  parser.Evaluate(\"x \u003c 1\", map[string]interface{}{\"x\": 1})\n  parser.Evaluate(\"x gt 1\", map[string]interface{}{\"x\": 1})\n\n  parser.Evaluate(\"x.a == 1 and x.b.c \u003c= 2\", map[string]interface{}{\n    \"x\": map[string]interface{}{\n       \"a\": 1,\n       \"b\": map[string]interface{}{\n          \"c\": 2,\n       },\n    },\n  })\n\n\n  parser.Evaluate(\"y == 4 and (x \u003e 1)\", map[string]interface{}{\"x\": 1})\n\n  parser.Evaluate(\"y == 4 and (x IN [1,2,3])\", map[string]interface{}{\"x\": 1})\n\n  parser.Evaluate(\"y == 4 and (x eq 1.2.3)\", map[string]interface{}{\"x\": \"1.2.3\"})\n\n```\n\n## Operations\n\nAll the operations can be written capitalized or lowercase (ex: `eq` or `EQ` can be used)\n\nLogical Operations supported are `and` `or`\n\nCompare Expression and their definitions\n\n| expression | meaning   | \n-------------|------------\n| eq         | equals to |\n| ==         | equals to |\n| ne         | not equal to |\n| !=         | not equal to |\n| lt         | less than |\n| \u003c          | less than |\n| gt         | greater than |\n| \u003e          | greater than |\n| le         | less than or equal to |\n| \u003c=          | less than or equal to  |\n| ge          | greater than or equal to|\n| \u003e=          | greater than or equal to|\n| co         | contains  |\n| sw         | starts with  |\n| ew         | ends with  |\n| in         | in a list  |\n| pr         | present, will be true if you have a key as true  |\n| not         | not of a logical expression  |\n\n## How to use it\n\nUse your dependency manager to import `github.com/nikunjy/rules/parser`. This will let you parse a rule and keep the parsed representation around.\nAlternatively, you can also use `github.com/nikunjy/rules` directly to call the root `Evaluate(string, map[string]interface{})` method.\n\nI would recommend importing `github.com/nikunjy/rules/parser`\n\n## How to extend the grammar\n\n1. Please look at this [antlr tutorial](https://tomassetti.me/antlr-mega-tutorial/#setup-antlr), the link will show you how to setup antlr.\n   The article has a whole lot of detail about antlr I encourage you to read it, you might also like [my blog post](https://medium.com/@nikunjyadav/generic-rules-engine-in-golang-using-antlr-d30a0d0bb565) about this repo.\n2. After taking a look at the antlr tutorial, you can extend the [JsonQuery.g4 file](https://github.com/nikunjy/rules/blob/master/parser/JsonQuery.g4).\n3. Compile the parser `antlr4 -Dlanguage=Go -visitor -no-listener JsonQuery.g4 -o ./` (Note: `-o` is the output directory, make sure all the stuff it generates is in the `parser` directory of the root repo folder)\n\n[ci-img]: https://api.travis-ci.org/nikunjy/rules.svg?branch=master\n[ci]: https://travis-ci.org/nikunjy/rules\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikunjy%2Frules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikunjy%2Frules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikunjy%2Frules/lists"}