Hunter0x7c7
2022-08-11 a82f9cb69f63aaeba40c024960deda7d75b9fece
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
package geodata
 
import (
    "strings"
 
    "github.com/v2fly/v2ray-core/v5/app/router/routercommon"
)
 
type AttributeList struct {
    matcher []AttributeMatcher
}
 
func (al *AttributeList) Match(domain *routercommon.Domain) bool {
    for _, matcher := range al.matcher {
        if !matcher.Match(domain) {
            return false
        }
    }
    return true
}
 
func (al *AttributeList) IsEmpty() bool {
    return len(al.matcher) == 0
}
 
func parseAttrs(attrs []string) *AttributeList {
    al := new(AttributeList)
    for _, attr := range attrs {
        trimmedAttr := strings.ToLower(strings.TrimSpace(attr))
        if len(trimmedAttr) == 0 {
            continue
        }
        al.matcher = append(al.matcher, BooleanMatcher(trimmedAttr))
    }
    return al
}
 
type AttributeMatcher interface {
    Match(*routercommon.Domain) bool
}
 
type BooleanMatcher string
 
func (m BooleanMatcher) Match(domain *routercommon.Domain) bool {
    for _, attr := range domain.Attribute {
        if strings.EqualFold(attr.GetKey(), string(m)) {
            return true
        }
    }
    return false
}