github.com/kelleygo/clashcore@v1.0.2/rules/common/domain_keyword.go (about) 1 package common 2 3 import ( 4 "strings" 5 6 C "github.com/kelleygo/clashcore/constant" 7 "golang.org/x/net/idna" 8 ) 9 10 type DomainKeyword struct { 11 *Base 12 keyword string 13 adapter string 14 } 15 16 func (dk *DomainKeyword) RuleType() C.RuleType { 17 return C.DomainKeyword 18 } 19 20 func (dk *DomainKeyword) Match(metadata *C.Metadata) (bool, string) { 21 domain := metadata.RuleHost() 22 return strings.Contains(domain, dk.keyword), dk.adapter 23 } 24 25 func (dk *DomainKeyword) Adapter() string { 26 return dk.adapter 27 } 28 29 func (dk *DomainKeyword) Payload() string { 30 return dk.keyword 31 } 32 33 func NewDomainKeyword(keyword string, adapter string) *DomainKeyword { 34 punycode, _ := idna.ToASCII(strings.ToLower(keyword)) 35 return &DomainKeyword{ 36 Base: &Base{}, 37 keyword: punycode, 38 adapter: adapter, 39 } 40 } 41 42 //var _ C.Rule = (*DomainKeyword)(nil)