4
4
[ ![ Code Coverage] ( https://scrutinizer-ci.com/g/antonmedv/expr/badges/coverage.png?b=master )] ( https://scrutinizer-ci.com/g/antonmedv/expr/?branch=master )
5
5
[ ![ GoDoc] ( https://godoc.org/github.com/antonmedv/expr?status.svg )] ( https://godoc.org/github.com/antonmedv/expr )
6
6
7
- Expr is an engine that can evaluate expressions.
7
+ ** Expr** package provides an engine that can compile and evaluate expressions.
8
+ An expression is a one-liner that returns a value (mostly, but not limited to, booleans).
9
+ It is designed for simplicity, speed and safety.
8
10
9
11
The purpose of the package is to allow users to use expressions inside configuration for more complex logic.
10
12
It is a perfect candidate for the foundation of a _ business rule engine_ .
@@ -51,8 +53,8 @@ go get -u github.com/antonmedv/expr
51
53
52
54
## Documentation
53
55
54
- * See [ ![ GoDoc ] ( https://godoc.org/github.com/antonmedv/expr?status.svg )] ( https://godoc.org/github.com/antonmedv/expr ) for developer documentation,
55
- * See [ The Expression Syntax] ( https://github.com/antonmedv/expr/wiki/The-Expression-Syntax ) page to learn the syntax of the Expr expressions .
56
+ * See [ docs ] ( docs ) for developer documentation.
57
+ * See [ The Expression Syntax] ( https://github.com/antonmedv/expr/wiki/The-Expression-Syntax ) page to learn the syntax.
56
58
57
59
## Examples
58
60
@@ -81,7 +83,7 @@ type Bar struct {
81
83
82
84
program , err := expr.Compile (" Foo + Bar.Value" , expr.Env (Env{}))
83
85
84
- output , err := expr.Run (program, Env {1 , Bar {2 }})
86
+ out , err := expr.Run (program, Env {1 , Bar {2 }})
85
87
```
86
88
87
89
Using env's methods as functions inside expressions.
@@ -95,9 +97,9 @@ func (e *Env) Title() string {
95
97
return strings.Title (e.Name )
96
98
}
97
99
98
- p , err := expr.Parse (` "Hello " + Title()` , expr.Env (&Env{}))
100
+ program , err := expr.Compile (` "Hello " + Title()` , expr.Env (&Env{}))
99
101
100
- out , err := expr.Run (p , &Env{" world" })
102
+ out , err := expr.Run (program , &Env{" world" })
101
103
```
102
104
103
105
Using embedded structs to construct env.
@@ -115,9 +117,9 @@ func (Helpers) Title(s string) string {
115
117
}
116
118
117
119
118
- p , err := expr.Parse (` "Hello " + Title(Name)` , expr.Env (Env{}))
120
+ program , err := expr.Compile (` "Hello " + Title(Name)` , expr.Env (Env{}))
119
121
120
- out , err := expr.Run (p , Env {" world" })
122
+ out , err := expr.Run (program , Env {" world" })
121
123
```
122
124
123
125
## Who is using Expr?
0 commit comments