-
Notifications
You must be signed in to change notification settings - Fork 14
/
expr.go
49 lines (38 loc) · 785 Bytes
/
expr.go
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
package gobatis
import (
"fmt"
"strings"
"github.com/antonmedv/expr"
)
func blank(arg interface{}) bool {
if nil == arg {
return true
}
res := fmt.Sprint(arg)
if res == "" {
return true
}
if strings.TrimSpace(res) == "" {
return true
}
return false
}
func eval(expression string, mapper map[string]interface{}) bool {
env := map[string]interface{}{
"$blank": blank,
}
for k, v := range mapper {
env[k] = v
}
program, err := expr.Compile(expression, expr.Env(env))
if err != nil {
LOG.Debug("[WARN]", "Expression:", expression, ">>> Compile result err:", err)
return false
}
ok, err := expr.Run(program, env)
if err != nil {
LOG.Debug("[WARN]", "Expression:", expression, ">>> eval result err:", err)
return false
}
return ok.(bool)
}