forked from maksymgaraiev/orwell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xgteql.go
48 lines (40 loc) · 884 Bytes
/
xgteql.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
package orwell
import (
"fmt"
)
// XGtEql func
func (*Orwell) XGtEql(gtField interface{}, gtValue int, eqlField interface{}, eqlValue interface{}) *xGtEql {
return &xGtEql{
gtField: gtField,
gtValue: gtValue,
eqlField: eqlField,
eqlValue: eqlValue,
msg: fmt.Sprintf("Validation error for 'XGtEql' rule"),
}
}
// xGtEql struct
type xGtEql struct {
gtField interface{}
gtValue int
eqlField interface{}
eqlValue interface{}
msg string
}
// Apply rule
func (r *xGtEql) 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) {
return fmt.Errorf(r.msg)
}
return nil
}