You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-20
Original file line number
Diff line number
Diff line change
@@ -12,32 +12,16 @@ This version includes a couple more features including, AND and OR composites an
12
12
13
13
```go
14
14
// Create a new instance of an engine with some default comparators
15
-
e:=NewEngine()
15
+
e, err:=NewJSONEngine(json.RawMessage(`{"composites":[{"operator":"or","rules":[{"comparator":"always-false","path":"user.name","value":"Trevor"},{"comparator":"eq","path":"user.name","value":"Trevor"}]}]}`))
16
+
if err != nil {
17
+
panic(err)
18
+
}
16
19
17
20
// Add a new, custom comparator
18
21
e = e.AddComparator("always-false", func(a, b interface{}) bool {
19
22
returnfalse
20
23
})
21
24
22
-
// Create composites, with rules for the engine to evaluate
23
-
e.Composites = []Composite{
24
-
Composite{
25
-
Operator: OperatorOr,
26
-
Rules: []Rule{
27
-
Rule{
28
-
Comparator: "always-false",
29
-
Path: "user.name",
30
-
Value: "Trevor",
31
-
},
32
-
Rule{
33
-
Comparator: "eq",
34
-
Path: "user.name",
35
-
Value: "Trevor",
36
-
},
37
-
},
38
-
},
39
-
}
40
-
41
25
// Give some properties, this map can be deeper and supports interfaces
e, err:=NewJSONEngine(json.RawMessage(`{"composites":[{"operator":"and","rules":[{"comparator":"contains","path":"address.bedroom.furniture","value":"tv"}]}]}`))
e, err:=NewJSONEngine(json.RawMessage(`{"composites":[{"operator":"and","rules":[{"comparator":"eq","path":"user.name","value":"Trevor"},{"comparator":"eq","path":"user.id","value":1234}]},{"operator":"or","rules":[{"comparator":"eq","path":"user.name","value":"Trevor"},{"comparator":"eq","path":"user.id","value":7}]}]}`))
e, err:=NewJSONEngine(json.RawMessage(`{"composites":[{"operator":"and","rules":[{"comparator":"contains","path":"user.favorites","value":"golang"}]}]}`))
0 commit comments