github.com/yaling888/clash@v1.53.0/rule/domain_keyword.go (about)

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