github.com/kelleygo/clashcore@v1.0.2/rules/common/domain.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 Domain struct { 11 *Base 12 domain string 13 adapter string 14 } 15 16 func (d *Domain) RuleType() C.RuleType { 17 return C.Domain 18 } 19 20 func (d *Domain) Match(metadata *C.Metadata) (bool, string) { 21 return metadata.RuleHost() == d.domain, d.adapter 22 } 23 24 func (d *Domain) Adapter() string { 25 return d.adapter 26 } 27 28 func (d *Domain) Payload() string { 29 return d.domain 30 } 31 32 func NewDomain(domain string, adapter string) *Domain { 33 punycode, _ := idna.ToASCII(strings.ToLower(domain)) 34 return &Domain{ 35 Base: &Base{}, 36 domain: punycode, 37 adapter: adapter, 38 } 39 } 40 41 //var _ C.Rule = (*Domain)(nil)