clash/rules/common/domain_keyword.go

41 lines
737 B
Go
Raw Normal View History

package common
2018-06-10 14:50:03 +00:00
import (
"strings"
C "github.com/Dreamacro/clash/constant"
)
type DomainKeyword struct {
2022-03-12 17:21:23 +00:00
*Base
keyword string
adapter string
2018-06-10 14:50:03 +00: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 14:50:03 +00:00
}
func (dk *DomainKeyword) Adapter() string {
return dk.adapter
}
2018-06-20 14:41:02 +00:00
func (dk *DomainKeyword) Payload() string {
return dk.keyword
2018-06-20 14:41:02 +00:00
}
2022-03-12 17:21:23 +00:00
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
2018-06-10 14:50:03 +00:00
return &DomainKeyword{
Base: &Base{},
keyword: strings.ToLower(keyword),
adapter: adapter,
2018-06-10 14:50:03 +00:00
}
}
2022-03-12 17:21:23 +00:00
//var _ C.Rule = (*DomainKeyword)(nil)