-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplitversionfilter.go
More file actions
44 lines (35 loc) · 1.04 KB
/
splitversionfilter.go
File metadata and controls
44 lines (35 loc) · 1.04 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
package specs
import (
"github.com/splitio/go-split-commons/v6/engine/grammar/matchers"
)
type SplitVersionFilter struct {
data map[string]map[string]bool
}
func NewSplitVersionFilter() SplitVersionFilter {
data := map[string]map[string]bool{
FLAG_V1_1: {matchers.MatcherTypeInLargeSegment: true},
}
data[FLAG_V1_0] = mergeMaps(map[string]bool{
matchers.MatcherEqualToSemver: true,
matchers.MatcherTypeLessThanOrEqualToSemver: true,
matchers.MatcherTypeGreaterThanOrEqualToSemver: true,
matchers.MatcherTypeBetweenSemver: true,
matchers.MatcherTypeInListSemver: true,
}, data[FLAG_V1_1])
return SplitVersionFilter{
data: data,
}
}
func (f *SplitVersionFilter) ShouldFilter(matcher string, apiVersion string) bool {
matchers, ok := f.data[apiVersion]
if !ok {
return false
}
return matchers[matcher]
}
func mergeMaps(versionMap map[string]bool, toMergeMap map[string]bool) map[string]bool {
for key, value := range toMergeMap {
versionMap[key] = value
}
return versionMap
}