Clash.Meta/rule/domain.go

49 lines
801 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
ruleExtra *C.RuleExtra
2018-09-09 15:01:46 +08:00
}
func (d *Domain) RuleType() C.RuleType {
return C.Domain
}
func (d *Domain) Match(metadata *C.Metadata) bool {
2018-09-30 12:25:52 +08:00
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 (d *Domain) ShouldResolveIP() bool {
return false
}
func (d *Domain) RuleExtra() *C.RuleExtra {
return d.ruleExtra
2021-07-01 22:49:29 +08:00
}
func NewDomain(domain string, adapter string, ruleExtra *C.RuleExtra) *Domain {
2018-09-09 15:01:46 +08:00
return &Domain{
domain: strings.ToLower(domain),
adapter: adapter,
ruleExtra: ruleExtra,
2018-09-09 15:01:46 +08:00
}
}