All Projects → huttotw → Grules

huttotw / Grules

Licence: apache-2.0
A simple, but expandable, rules engine for Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Grules

Json Rules Engine
A rules engine expressed in JSON
Stars: ✭ 1,159 (+1683.08%)
Mutual labels:  rules-engine, json
Jwalk
Walk through JSON with Go
Stars: ✭ 64 (-1.54%)
Mutual labels:  json
I18n Generator
i18n json files generator for node, web browser and command line
Stars: ✭ 60 (-7.69%)
Mutual labels:  json
Proposal Well Formed Stringify
Proposal to prevent JSON.stringify from returning ill-formed strings
Stars: ✭ 61 (-6.15%)
Mutual labels:  json
Kubernetes Operator
kubernetes-operator is a control plane and manage all kubernetes cluster lifecycle.
Stars: ✭ 61 (-6.15%)
Mutual labels:  operator
Low Latency Android Ios Linux Windows Tvos Macos Interactive Audio Platform
🇸Superpowered Audio, Networking and Cryptographics SDKs. High performance and cross platform on Android, iOS, macOS, tvOS, Linux, Windows and modern web browsers.
Stars: ✭ 1,121 (+1624.62%)
Mutual labels:  json
Govalid
Data validation library for golang. [MIGRATING TO NEW ADDRESS]
Stars: ✭ 59 (-9.23%)
Mutual labels:  json
Countries States Cities Database
🌍 World countries, states, regions, provinces, cities, towns in JSON, SQL, XML, PLIST, YAML, and CSV. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Timezones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency. #countries #states #cities
Stars: ✭ 1,130 (+1638.46%)
Mutual labels:  json
Etcd Cluster Operator
A controller to deploy and manage etcd clusters inside of Kubernetes
Stars: ✭ 63 (-3.08%)
Mutual labels:  operator
Whc datamodelfactory
Mac上iOS开发辅助工具,快速把json/xml数据转换生成对应模型类属性,省去麻烦手动创建,提高开发效率。Mac iOS development aid, quickly put the json/XML data transformation generates the corresponding model class attribute, save trouble created manually, improve the development efficiency.
Stars: ✭ 1,118 (+1620%)
Mutual labels:  json
Ediengine
Simple .NET EDI X12 Reader, Writer and Validator. EDI JSON Serialization and Deserialization. Written in C#
Stars: ✭ 61 (-6.15%)
Mutual labels:  json
Gophergameserver
🏆 Feature packed, easy-to-use game server API for Go back-ends and Javascript clients. Tutorials and examples included!
Stars: ✭ 61 (-6.15%)
Mutual labels:  json
Hibernate Types
The Hibernate Types library gives you extra types that are not supported by the Hibernate ORM core.
Stars: ✭ 1,122 (+1626.15%)
Mutual labels:  json
Njson
Unmarshal/Decode nested JSON by JSON Path
Stars: ✭ 61 (-6.15%)
Mutual labels:  json
Callbag Map Promise
Callbag map promise
Stars: ✭ 64 (-1.54%)
Mutual labels:  operator
Funcj
Assorted functional-oriented data structures and algorithms for Java.
Stars: ✭ 60 (-7.69%)
Mutual labels:  json
Cssparser.js
cssparser.js is a parser that generate json from css with matched orders & structures.
Stars: ✭ 61 (-6.15%)
Mutual labels:  json
Euler
Swift Custom Operators for Mathematical Notation
Stars: ✭ 1,123 (+1627.69%)
Mutual labels:  operator
Inspec tools
A command-line and ruby API of utilities, converters and tools for creating, converting and processing security baseline formats, results and data
Stars: ✭ 65 (+0%)
Mutual labels:  json
Netkan
Metadata files used by the NetKAN/CKAN indexer
Stars: ✭ 64 (-1.54%)
Mutual labels:  json
grules

Introduction

This package was created with inspiration from Thomas' go-ruler to run a simple set of rules against an entity.

This version includes a couple more features including, AND and OR composites and the ability to add custom comparators.

Note: This package only compares two types: string and float64, this plays nicely with encoding/json.

Example

// Create a new instance of an engine with some default comparators
e, err := NewJSONEngine(json.RawMessage(`{"composites":[{"operator":"or","rules":[{"comparator":"always-false","path":"user.name","value":"Trevor"},{"comparator":"eq","path":"user.name","value":"Trevor"}]}]}`))
if err != nil {
    panic(err)
}

// Add a new, custom comparator
e = e.AddComparator("always-false", func(a, b interface{}) bool {
    return false
})

// Give some properties, this map can be deeper and supports interfaces
props := map[string]interface{}{
    "user": map[string]interface{}{
        "name": "Trevor",
    }
}

// Run the engine on the props
res := e.Evaluate(props)
// res == true

Comparators

  • eq will return true if a == b
  • neq will return true if a != b
  • lt will return true if a < b
  • lte will return true if a <= b
  • gt will return true if a > b
  • gte will return true if a >= b
  • contains will return true if a contains b
  • ncontains will return true if a does not contain b
  • oneof will return true if a is one of b
  • noneof will return true if a is not one of b
  • regex will return true if a matches b

contains and ncontains work for substring comparisons as well as item-in-collection comparisons.

When used for item-in-collection comparisons, contains expects the first argument to be a slice. contains is different than oneof in that oneof expects the second argument to be a slice.

Benchmarks

Benchmark N Speed Used Allocs
BenchmarkEqual-12 650602549 5.52 ns/op 0 B/op 0 allocs/op
BenchmarkNotEqual-12 876894124 4.09 ns/op 0 B/op 0 allocs/op
BenchmarkLessThan-12 1000000000 2.84 ns/op 0 B/op 0 allocs/op
BenchmarkLessThanEqual-12 1000000000 2.57 ns/op 0 B/op 0 allocs/op
BenchmarkGreaterThan-12 1000000000 2.07 ns/op 0 B/op 0 allocs/op
BenchmarkGreaterThanEqual-12 1000000000 2.86 ns/op 0 B/op 0 allocs/op
BenchmarkRegex-12 4524237 793 ns/op 753 B/op 11 allocs/op
BenchmarkRegexPhone-12 1000000 3338 ns/op 3199 B/op 30 allocs/op
BenchmarkContains-12 499627219 7.16 ns/op 0 B/op 0 allocs/op
BenchmarkStringContains-12 405497102 8.87 ns/op 0 B/op 0 allocs/op
BenchmarkContainsLong50000-12 18992 184016 ns/op 0 B/op 0 allocs/op
BenchmarkNotContains-12 292932907 12.3 ns/op 0 B/op 0 allocs/op
BenchmarkStringNotContains-12 392618857 9.14 ns/op 0 B/op 0 allocs/op
BenchmarkNotContainsLong50000-12 19243 191787 ns/op 0 B/op 0 allocs/op
BenchmarkOneOf-12 1000000000 1.80 ns/op 0 B/op 0 allocs/op
BenchmarkNoneOf-12 1000000000 1.79 ns/op 0 B/op 0 allocs/op
BenchmarkPluckShallow-12 85997188 41.6 ns/op 16 B/op 1 allocs/op
BenchmarkPluckDeep-12 18789103 194 ns/op 112 B/op 1 allocs/op
BenchmarkRule_evaluate-12 69558996 51.1 ns/op 16 B/op 1 allocs/op
BenchmarkComposite_evaluate-12 59484760 55.7 ns/op 16 B/op 1 allocs/op
BenchmarkEngine_Evaluate-12 47892318 75.0 ns/op 16 B/op 1 allocs/op

To run benchmarks:

go test -run none -bench . -benchtime 3s -benchmem

All benchmarks were run on:

MacOS High Sierra 2.6Ghz Intel Core i7 16 GB 2400 MHz DDR4

License

Copyright © 2019 Trevor Hutto

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].