Repository navigation
Expand file tree
/
Copy pathdoc.go
More file actions
75 lines (62 loc) · 1.54 KB
/
Copy pathdoc.go
File metadata and controls
75 lines (62 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2025 Moath Almallahi. All rights reserved.
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.
/*
Package rulesengine defines the different types needed for the rule definition
and the evaluation results, as well as the execution method which triggers the
evaluation.
# Rule
The primary type in the API is [Rule]. A Rule describes a single or a
group of rules:
package testpackage
import (
"fmt"
"github.com/goglue/rulesengine"
)
func run() {
rule := rulesengine.Rule{
Operator: rulesengine.And,
Children: []rulesengine.Rule{
{
Operator: rulesengine.And,
Children: []rulesengine.Rule{
{
Field: "user.name",
Operator: rulesengine.LengthGt,
Value: 2,
},
{
Field: "user.name",
Operator: rulesengine.LengthLt,
Value: 25,
},
},
},
{
Field: "user.age",
Operator: rulesengine.Gte,
Value: 21,
},
{
Field: "user.country",
Operator: rulesengine.Eq,
Value: "DE",
},
},
}
data := map[string]any{
"user": map[string]any{
"name": "Test",
"age": 25,
"country": "DE",
},
}
result := rulesengine.Evaluate(rule, data, rulesengine.DefaultOptions())
fmt.Println("Result:", result.Result) // true
}
# RuleResult
A [RuleResult] describes the result of a rule evaluation, the structure contains
the final result in boolean type, the mismatching value (if any), the time taken
to evaluate the rule.
*/
package rulesengine