Clash.Meta/rules/common/domain.go

42 lines
686 B
Go
Raw Normal View History

package common
2018-09-09 15:01:46 +08:00
import (
"strings"
2023-11-03 21:01:45 +08:00
C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
2018-09-09 15:01:46 +08:00
)
type Domain struct {
2022-03-13 01:21:23 +08:00
*Base
domain string
adapter string
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, string) {
return metadata.RuleHost() == d.domain, d.adapter
2018-09-09 15:01:46 +08:00
}
func (d *Domain) Adapter() string {
return d.adapter
}
func (d *Domain) Payload() string {
return d.domain
2018-09-09 15:01:46 +08:00
}
2022-03-13 01:21:23 +08:00
func NewDomain(domain string, adapter string) *Domain {
punycode, _ := idna.ToASCII(strings.ToLower(domain))
2018-09-09 15:01:46 +08:00
return &Domain{
Base: &Base{},
domain: punycode,
adapter: adapter,
2018-09-09 15:01:46 +08:00
}
}
2022-03-13 01:21:23 +08:00
//var _ C.Rule = (*Domain)(nil)