-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.go
56 lines (43 loc) · 1.3 KB
/
checker.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
53
54
55
56
package fet
import "time"
// Checker is an interface that defines
// how to check a filter has to be eliminated or not.
type Checker interface {
Check(key string, value interface{}) bool
}
type CheckerFunc func(key string, value interface{}) bool
func (cf CheckerFunc) Check(key string, value interface{}) bool {
return cf(key, value)
}
// IfNotNil checks if the given value is not nil.
var IfNotNil Checker = CheckerFunc(func(key string, value interface{}) bool {
return value != nil
})
// IfNotZero checks if the given value is not zero.
var IfNotZero Checker = CheckerFunc(func(key string, value interface{}) bool {
return value != 0
})
// IfNotEmpty checks if the given value is not a empty empty string.
var IfNotEmpty Checker = CheckerFunc(func(key string, value interface{}) bool {
return value != ""
})
// IfNotZeroTime checks if the given value is not zero time.
// if value type is not time.Time then it will return true.
var IfNotZeroTime Checker = CheckerFunc(func(key string, value interface{}) bool {
var (
t time.Time
ok bool
)
if t, ok = value.(time.Time); !ok {
return true
}
return !t.IsZero()
})
func checkFilter(key string, value interface{}, checkers ...Checker) bool {
for _, checker := range checkers {
if !checker.Check(key, value) {
return false
}
}
return true
}