forked from maksymgaraiev/orwell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xgteqlor.go
55 lines (47 loc) · 1.01 KB
/
xgteqlor.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
package orwell
import (
"fmt"
)
// XGtEqlOr func
func (*Orwell) XGtEqlOr(gtField interface{}, gtValue int, eqlField interface{}, eqlValue interface{}, ors ...interface{}) *xGtEqlOr {
return &xGtEqlOr{
gtField: gtField,
gtValue: gtValue,
eqlField: eqlField,
eqlValue: eqlValue,
ors: ors,
msg: fmt.Sprintf("Validation error for 'XGtEqlOr' rule"),
}
}
// xGtEqlOr struct
type xGtEqlOr struct {
gtField interface{}
gtValue int
eqlField interface{}
eqlValue interface{}
ors []interface{}
msg string
}
// Apply rule
func (r *xGtEqlOr) Apply(value interface{}) error {
if !NOE(value) {
return nil
}
gtField, isNil := IsNil(r.gtField)
if isNil || IsEmpty(gtField) {
return nil
}
gtFieldInt64, err := ToInt64(gtField)
if err != nil {
return fmt.Errorf("%s: %s", r.msg, err.Error())
}
if gtFieldInt64 > int64(r.gtValue) && DeepEqual(r.eqlField, r.eqlValue) {
for _, or := range r.ors {
if !NOE(or) {
return nil
}
}
return fmt.Errorf(r.msg)
}
return nil
}