@@ -2,6 +2,9 @@ package types
2
2
3
3
import (
4
4
"fmt"
5
+ "strconv"
6
+
7
+ "github.com/drone/ff-golang-server-sdk/log"
5
8
)
6
9
7
10
// Integer type for clause attribute evaluation
@@ -17,82 +20,86 @@ func NewInteger(value interface{}) (*Integer, error) {
17
20
return nil , fmt .Errorf ("%v: cant cast to a integer" , ErrWrongTypeAssertion )
18
21
}
19
22
20
- func (n Integer ) operator (value interface {}, fn func (int64 ) bool ) bool {
21
- num , ok := value .([]int64 )
22
- if ok {
23
- return fn (num [0 ])
23
+ // intOperator takes the first element from the slice, converts it to a int64 and passes to fn for processing.
24
+ // we ignore any additional elements if they exist.
25
+ func intOperator (value []string , fn func (int64 ) bool ) bool {
26
+ if len (value ) > 0 {
27
+ if i , err := strconv .ParseInt (value [0 ], 10 , 64 ); err == nil {
28
+ if fn (i ) {
29
+ return true
30
+ }
31
+ }
32
+ log .Warnf ("input contains invalid value for integer comparisons: %s\n " , value )
24
33
}
34
+
25
35
return false
26
36
}
27
37
28
38
// StartsWith always return false
29
- func (n Integer ) StartsWith (interface {} ) bool {
39
+ func (n Integer ) StartsWith ([] string ) bool {
30
40
return false
31
41
}
32
42
33
43
// EndsWith always return false
34
- func (n Integer ) EndsWith (interface {} ) bool {
44
+ func (n Integer ) EndsWith ([] string ) bool {
35
45
return false
36
46
}
37
47
38
48
// Match always return false
39
- func (n Integer ) Match (interface {} ) bool {
49
+ func (n Integer ) Match ([] string ) bool {
40
50
return false
41
51
}
42
52
43
53
// Contains always return false
44
- func (n Integer ) Contains (interface {} ) bool {
54
+ func (n Integer ) Contains ([] string ) bool {
45
55
return false
46
56
}
47
57
48
58
// EqualSensitive always return false
49
- func (n Integer ) EqualSensitive (interface {} ) bool {
59
+ func (n Integer ) EqualSensitive ([] string ) bool {
50
60
return false
51
61
}
52
62
53
63
// Equal check if the number and value are equal
54
- func (n Integer ) Equal (value interface {} ) bool {
55
- return n . operator (value , func (f int64 ) bool {
64
+ func (n Integer ) Equal (value [] string ) bool {
65
+ return intOperator (value , func (f int64 ) bool {
56
66
return int64 (n ) == f
57
67
})
58
68
}
59
69
60
70
// GreaterThan checks if the number is greater than the value
61
- func (n Integer ) GreaterThan (value interface {} ) bool {
62
- return n . operator (value , func (f int64 ) bool {
71
+ func (n Integer ) GreaterThan (value [] string ) bool {
72
+ return intOperator (value , func (f int64 ) bool {
63
73
return int64 (n ) > f
64
74
})
65
75
}
66
76
67
77
// GreaterThanEqual checks if the number is greater or equal than the value
68
- func (n Integer ) GreaterThanEqual (value interface {} ) bool {
69
- return n . operator (value , func (f int64 ) bool {
78
+ func (n Integer ) GreaterThanEqual (value [] string ) bool {
79
+ return intOperator (value , func (f int64 ) bool {
70
80
return int64 (n ) >= f
71
81
})
72
82
}
73
83
74
84
// LessThan checks if the number is less than the value
75
- func (n Integer ) LessThan (value interface {} ) bool {
76
- return n . operator (value , func (f int64 ) bool {
85
+ func (n Integer ) LessThan (value [] string ) bool {
86
+ return intOperator (value , func (f int64 ) bool {
77
87
return int64 (n ) < f
78
88
})
79
89
}
80
90
81
91
// LessThanEqual checks if the number is less or equal than the value
82
- func (n Integer ) LessThanEqual (value interface {} ) bool {
83
- return n . operator (value , func (f int64 ) bool {
92
+ func (n Integer ) LessThanEqual (value [] string ) bool {
93
+ return intOperator (value , func (f int64 ) bool {
84
94
return int64 (n ) <= f
85
95
})
86
96
}
87
97
88
98
// In checks if the number exist in slice of numbers (value)
89
- func (n Integer ) In (value interface {}) bool {
90
- array , ok := value .([]interface {})
91
- if ok {
92
- for _ , val := range array {
93
- if n .Equal (val ) {
94
- return true
95
- }
99
+ func (n Integer ) In (value []string ) bool {
100
+ for _ , x := range value {
101
+ if n .Equal ([]string {x }) {
102
+ return true
96
103
}
97
104
}
98
105
return false
0 commit comments