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

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