-
Notifications
You must be signed in to change notification settings - Fork 1
/
op_and_or.go
38 lines (34 loc) · 915 Bytes
/
op_and_or.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
package cond
import (
"reflect"
)
const opAnd Operator = "$and"
const opOr Operator = "$or"
// all sub conds should be true. eg: { "$and": [{}, {}] }
func opAndFunc(s *State, l string, op Operator, r interface{}, reg map[string]interface{}) bool {
if reflect.TypeOf(r).Kind() != reflect.Slice {
panic("right value of OP $and must be slice type")
}
if subCond, ok := r.([]Cond); ok {
for _, v := range subCond {
if !opMainFunc(s, "", "", v, reg) {
return false
}
}
}
return true
}
// one of subconds should be true. eg: { "$or": [{}, {}] }
func opOrFunc(s *State, l string, op Operator, r interface{}, reg map[string]interface{}) bool {
if reflect.TypeOf(r).Kind() != reflect.Slice {
panic("right value of OP $or must be slice type")
}
if subCond, ok := r.([]Cond); ok {
for _, v := range subCond {
if opMainFunc(s, "", "", v, reg) {
return true
}
}
}
return false
}