-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgtoet.go
More file actions
61 lines (54 loc) · 1.77 KB
/
Copy pathgtoet.go
File metadata and controls
61 lines (54 loc) · 1.77 KB
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
57
58
59
60
61
package matchers
import (
"fmt"
"github.com/splitio/go-split-commons/v7/engine/grammar/matchers/datatypes"
)
// GreaterThanOrEqualToMatcher will match if two numbers or two datetimes are equal
type GreaterThanOrEqualToMatcher struct {
Matcher
ComparisonDataType string
ComparisonValue int64
}
// Match will match if the comparisonValue is greater than or equal to the matchingValue
func (m *GreaterThanOrEqualToMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool {
matchingRaw, err := m.matchingKey(key, attributes)
if err != nil {
m.logger.Warning(fmt.Sprintf("GreaterThanOrEqualToMatcher: %s", err.Error()))
return false
}
matchingValue, ok := matchingRaw.(int64)
if !ok {
var asInt int
asInt, ok = matchingRaw.(int)
if ok {
matchingValue = int64(asInt)
}
}
if !ok {
m.logger.Error("GreaterThanOrEqualToMatcher: Cannot type-assert key matching key to int")
return false
}
var comparisonValue int64
switch m.ComparisonDataType {
case datatypes.Number:
comparisonValue = m.ComparisonValue
case datatypes.Datetime:
matchingValue = datatypes.ZeroSecondsTS(matchingValue)
comparisonValue = datatypes.ZeroSecondsTS(datatypes.TsFromJava(m.ComparisonValue))
default:
m.logger.Error("GreaterThanOrEqualToMatcher: Incorrect attribute type")
return false
}
return matchingValue >= comparisonValue
}
// NewGreaterThanOrEqualToMatcher returns a pointer to a new instance of GreaterThanOrEqualToMatcher
func NewGreaterThanOrEqualToMatcher(negate bool, cmpVal int64, cmpType string, attributeName *string) *GreaterThanOrEqualToMatcher {
return &GreaterThanOrEqualToMatcher{
Matcher: Matcher{
negate: negate,
attributeName: attributeName,
},
ComparisonValue: cmpVal,
ComparisonDataType: cmpType,
}
}