github.com/chwjbn/xclash@v0.2.0/rule/domain_keyword.go (about)

     1  package rules
     2  
     3  import (
     4  	"strings"
     5  
     6  	C "github.com/chwjbn/xclash/constant"
     7  )
     8  
     9  type DomainKeyword struct {
    10  	keyword string
    11  	adapter string
    12  }
    13  
    14  func (dk *DomainKeyword) RuleType() C.RuleType {
    15  	return C.DomainKeyword
    16  }
    17  
    18  func (dk *DomainKeyword) Match(metadata *C.Metadata) bool {
    19  	if metadata.AddrType != C.AtypDomainName {
    20  		return false
    21  	}
    22  	domain := metadata.Host
    23  	return strings.Contains(domain, dk.keyword)
    24  }
    25  
    26  func (dk *DomainKeyword) Adapter() string {
    27  	return dk.adapter
    28  }
    29  
    30  func (dk *DomainKeyword) Payload() string {
    31  	return dk.keyword
    32  }
    33  
    34  func (dk *DomainKeyword) ShouldResolveIP() bool {
    35  	return false
    36  }
    37  
    38  func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
    39  	return &DomainKeyword{
    40  		keyword: strings.ToLower(keyword),
    41  		adapter: adapter,
    42  	}
    43  }