github.com/igoogolx/clash@v1.19.8/rule/domain_suffix.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 = (*DomainSuffix)(nil)
    11  
    12  type DomainSuffix struct {
    13  	suffix  string
    14  	adapter string
    15  }
    16  
    17  func (ds *DomainSuffix) RuleType() C.RuleType {
    18  	return C.DomainSuffix
    19  }
    20  
    21  func (ds *DomainSuffix) Match(metadata *C.Metadata) bool {
    22  	domain := metadata.Host
    23  	return strings.HasSuffix(domain, "."+ds.suffix) || domain == ds.suffix
    24  }
    25  
    26  func (ds *DomainSuffix) Adapter() string {
    27  	return ds.adapter
    28  }
    29  
    30  func (ds *DomainSuffix) Payload() string {
    31  	return ds.suffix
    32  }
    33  
    34  func (ds *DomainSuffix) ShouldResolveIP() bool {
    35  	return false
    36  }
    37  
    38  func (ds *DomainSuffix) ShouldFindProcess() bool {
    39  	return false
    40  }
    41  
    42  func NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
    43  	return &DomainSuffix{
    44  		suffix:  strings.ToLower(suffix),
    45  		adapter: adapter,
    46  	}
    47  }