mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-19 16:30:07 +08:00
Some checks are pending
Test / test (1.20, macos-13) (push) Waiting to run
Test / test (1.20, macos-latest) (push) Waiting to run
Test / test (1.20, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.20, ubuntu-latest) (push) Waiting to run
Test / test (1.20, windows-latest) (push) Waiting to run
Test / test (1.21, macos-13) (push) Waiting to run
Test / test (1.21, macos-latest) (push) Waiting to run
Test / test (1.21, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.21, ubuntu-latest) (push) Waiting to run
Test / test (1.21, windows-latest) (push) Waiting to run
Test / test (1.22, macos-13) (push) Waiting to run
Test / test (1.22, macos-latest) (push) Waiting to run
Test / test (1.22, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.22, ubuntu-latest) (push) Waiting to run
Test / test (1.22, windows-latest) (push) Waiting to run
Test / test (1.23, macos-13) (push) Waiting to run
Test / test (1.23, macos-latest) (push) Waiting to run
Test / test (1.23, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.23, ubuntu-latest) (push) Waiting to run
Test / test (1.23, windows-latest) (push) Waiting to run
Test / test (1.24, macos-13) (push) Waiting to run
Test / test (1.24, macos-latest) (push) Waiting to run
Test / test (1.24, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.24, ubuntu-latest) (push) Waiting to run
Test / test (1.24, windows-latest) (push) Waiting to run
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
46 lines
871 B
Go
46 lines
871 B
Go
package common
|
|
|
|
import (
|
|
C "github.com/metacubex/mihomo/constant"
|
|
|
|
"github.com/dlclark/regexp2"
|
|
)
|
|
|
|
type DomainRegex struct {
|
|
*Base
|
|
regex *regexp2.Regexp
|
|
adapter string
|
|
}
|
|
|
|
func (dr *DomainRegex) RuleType() C.RuleType {
|
|
return C.DomainRegex
|
|
}
|
|
|
|
func (dr *DomainRegex) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
|
domain := metadata.RuleHost()
|
|
match, _ := dr.regex.MatchString(domain)
|
|
return match, dr.adapter
|
|
}
|
|
|
|
func (dr *DomainRegex) Adapter() string {
|
|
return dr.adapter
|
|
}
|
|
|
|
func (dr *DomainRegex) Payload() string {
|
|
return dr.regex.String()
|
|
}
|
|
|
|
func NewDomainRegex(regex string, adapter string) (*DomainRegex, error) {
|
|
r, err := regexp2.Compile(regex, regexp2.IgnoreCase)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &DomainRegex{
|
|
Base: &Base{},
|
|
regex: r,
|
|
adapter: adapter,
|
|
}, nil
|
|
}
|
|
|
|
//var _ C.Rule = (*DomainRegex)(nil)
|