mihomo/rules/common/domain_keyword.go

43 lines
802 B
Go
Raw Normal View History

package common
2018-06-10 22:50:03 +08:00
import (
"strings"
2023-11-03 21:01:45 +08:00
C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
2018-06-10 22:50:03 +08:00
)
type DomainKeyword struct {
2022-03-13 01:21:23 +08:00
*Base
keyword string
adapter string
2018-06-10 22:50:03 +08:00
}
func (dk *DomainKeyword) RuleType() C.RuleType {
return C.DomainKeyword
}
func (dk *DomainKeyword) Match(metadata *C.Metadata) (bool, string) {
domain := metadata.RuleHost()
return strings.Contains(domain, dk.keyword), dk.adapter
2018-06-10 22:50:03 +08:00
}
func (dk *DomainKeyword) Adapter() string {
return dk.adapter
}
2018-06-20 22:41:02 +08:00
func (dk *DomainKeyword) Payload() string {
return dk.keyword
2018-06-20 22:41:02 +08:00
}
2022-03-13 01:21:23 +08:00
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
punycode, _ := idna.ToASCII(strings.ToLower(keyword))
2018-06-10 22:50:03 +08:00
return &DomainKeyword{
Base: &Base{},
keyword: punycode,
adapter: adapter,
2018-06-10 22:50:03 +08:00
}
}
2022-03-13 01:21:23 +08:00
//var _ C.Rule = (*DomainKeyword)(nil)