hopkinsth / go-ruler Goto Github PK
View Code? Open in Web Editor NEWbasic rules engine for go
License: Apache License 2.0
basic rules engine for go
License: Apache License 2.0
Hi,
Are you going to implement combination of rulesets?
The original ruler (https://github.com/RedVentures/ruler) does that..
Thanks..
Best regards..
It's used pretty often and probably doesn't need to use a regular expression
ALSO: it would be cool if it supported looking through a slice of things instead of just strings
Out of the other rule packages, I found this the best one for my needs. So thank you for developing it.
I have one use-case which I'm sure complicates things further.
I needed the ability to match multiple values within a rule.
For example. I may have the requirement of:
Expected -
People: Elon Musk OR Bill Gates OR Marissa Mayer
AND
Gender: Male
Actual -
People: Elon Musk
Gender: Male
I modified the compare method in ruler.go.
case "eq":
if strings.Contains(expected.(string), ",") {
sExpected := strings.Split(expected.(string), ",")
for _, item := range sExpected {
if strings.EqualFold(actual.(string), item) {
return true
}
}
return false
}
return actual == expected
Here is an example:
package main
import "github.com/hopkinsth/go-ruler"
import "fmt"
func main() {
// can also build rules programmatically
engine := ruler.NewRuler(nil)
engine.Rule("name").Eq("Elon Musk,Bill Gates,Marissa Mayer")
engine.Rule("gender").Eq("male")
context := map[string]interface{}{
"name": "Bill Gates",
"gender": "male",
}
result := engine.Test(context)
fmt.Println(result == true)
}
Or perhaps you want to do something else? But maybe you'll come up with something better and that all other compare methods can use.
Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.