2021-03-24 15:01:20 +00:00
|
|
|
package geosite
|
|
|
|
|
2021-04-08 05:19:25 +00:00
|
|
|
import "strings"
|
|
|
|
|
2021-03-24 15:01:20 +00:00
|
|
|
type AttributeList struct {
|
|
|
|
matcher []AttributeMatcher
|
|
|
|
}
|
|
|
|
|
|
|
|
func (al *AttributeList) Match(domain *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
|
|
|
|
}
|
|
|
|
|
|
|
|
type AttributeMatcher interface {
|
|
|
|
Match(*Domain) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type BooleanMatcher string
|
|
|
|
|
|
|
|
func (m BooleanMatcher) Match(domain *Domain) bool {
|
|
|
|
for _, attr := range domain.Attribute {
|
2021-04-08 05:19:25 +00:00
|
|
|
if strings.EqualFold(attr.GetKey(), string(m)) {
|
2021-03-24 15:01:20 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|