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

     1  package rules
     2  
     3  import (
     4  	"strings"
     5  
     6  	C "github.com/chwjbn/xclash/constant"
     7  )
     8  
     9  type DomainSuffix struct {
    10  	suffix  string
    11  	adapter string
    12  }
    13  
    14  func (ds *DomainSuffix) RuleType() C.RuleType {
    15  	return C.DomainSuffix
    16  }
    17  
    18  func (ds *DomainSuffix) Match(metadata *C.Metadata) bool {
    19  	if metadata.AddrType != C.AtypDomainName {
    20  		return false
    21  	}
    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 NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
    39  	return &DomainSuffix{
    40  		suffix:  strings.ToLower(suffix),
    41  		adapter: adapter,
    42  	}
    43  }