github.com/igoogolx/clash@v1.19.8/rule/domain_keyword.go (about)

     1  package rules
     2  
     3  import (
     4  	"strings"
     5  
     6  	C "github.com/igoogolx/clash/constant"
     7  )
     8  
     9  // Implements C.Rule
    10  var _ C.Rule = (*DomainKeyword)(nil)
    11  
    12  type DomainKeyword struct {
    13  	keyword string
    14  	adapter string
    15  }
    16  
    17  func (dk *DomainKeyword) RuleType() C.RuleType {
    18  	return C.DomainKeyword
    19  }
    20  
    21  func (dk *DomainKeyword) Match(metadata *C.Metadata) bool {
    22  	return strings.Contains(metadata.Host, dk.keyword)
    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 (dk *DomainKeyword) ShouldResolveIP() bool {
    34  	return false
    35  }
    36  
    37  func (dk *DomainKeyword) ShouldFindProcess() bool {
    38  	return false
    39  }
    40  
    41  func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
    42  	return &DomainKeyword{
    43  		keyword: strings.ToLower(keyword),
    44  		adapter: adapter,
    45  	}
    46  }