mihomo/rules/common/domain_keyword.go

41 lines
738 B
Go
Raw Permalink 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"
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 {
2018-06-10 22:50:03 +08:00
return &DomainKeyword{
Base: &Base{},
keyword: strings.ToLower(keyword),
adapter: adapter,
2018-06-10 22:50:03 +08:00
}
}
2022-03-13 01:21:23 +08:00
//var _ C.Rule = (*DomainKeyword)(nil)