clash/rules/domain.go

39 lines
597 B
Go
Raw Normal View History

2018-09-09 15:01:46 +08:00
package rules
import (
"strings"
2018-09-09 15:01:46 +08:00
C "github.com/Dreamacro/clash/constant"
)
type Domain struct {
domain string
adapter string
}
func (d *Domain) RuleType() C.RuleType {
return C.Domain
}
2018-09-30 12:25:52 +08:00
func (d *Domain) IsMatch(metadata *C.Metadata) bool {
if metadata.AddrType != C.AtypDomainName {
2018-09-09 15:01:46 +08:00
return false
}
2018-09-30 12:25:52 +08:00
return metadata.Host == d.domain
2018-09-09 15:01:46 +08:00
}
func (d *Domain) Adapter() string {
return d.adapter
}
func (d *Domain) Payload() string {
return d.domain
}
func NewDomain(domain string, adapter string) *Domain {
return &Domain{
domain: strings.ToLower(domain),
2018-09-09 15:01:46 +08:00
adapter: adapter,
}
}