-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
58 lines (52 loc) · 999 Bytes
/
filter.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
56
57
58
package main
type Filter struct {
Name string
Matches []string
Keep bool
}
func (f *Filter) filterIn(attributes map[string]string) bool {
value, ok := attributes[f.Name]
if f.Keep && !ok {
return false
}
for _, match := range f.Matches {
if value == match && f.Keep {
return true
}
}
return false
}
type FilterChain struct {
OperatorOr bool
FilterChains []FilterChain
Filters []Filter
}
func (fc *FilterChain) filterIn(attributes map[string]string) bool {
switch fc.OperatorOr {
case true:
for _, chain := range fc.FilterChains {
if chain.filterIn(attributes) {
return true
}
}
for _, filter := range fc.Filters {
if filter.filterIn(attributes) {
return true
}
}
return false
case false:
for _, chain := range fc.FilterChains {
if !chain.filterIn(attributes) {
return false
}
}
for _, filter := range fc.Filters {
if !filter.filterIn(attributes) {
return false
}
}
return true
}
return false
}