-
Notifications
You must be signed in to change notification settings - Fork 1
/
op_depend.go
52 lines (47 loc) · 1.05 KB
/
op_depend.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
50
51
52
package cond
const opDepend Operator = "$depend"
// when the type of right value is struct (map), we can not get the operator until the right value is parsed
// eg:
// {
// "key": {"$gt":100}
// }
func opDependFunc(s *State, l string, op Operator, r interface{}, reg map[string]interface{}) bool {
if l == "" {
panic("$depend l value can't be empty")
}
rvals, ok := r.(map[string]interface{})
if !ok {
rvals, ok = r.(Cond)
if !ok {
panic("$depend right value must be map[string]interface{}")
}
}
for k, v := range rvals {
kop := Operator(k)
switch kop {
case opEQ, opGT, opGTE, opLT, opLTE, opNE:
if !opCompareFunc(s, l, kop, v, reg) {
return false
}
case opIn:
if !opInfunc(s, l, kop, v, reg) {
return false
}
case opNin:
if !opNinfunc(s, l, kop, v, reg) {
return false
}
case opRegex:
if !opRegexFunc(s, l, kop, v, reg) {
return false
}
case opContain:
if !opContainFunc(s, l, kop, v, reg) {
return false
}
default:
panic("$depend right OP can't be " + k)
}
}
return true
}