mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-27 20:45:44 +08:00
2d1c031ce0
1.修复部分空指针问题 2.修改go.mod
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package provider
|
|
|
|
import (
|
|
"fmt"
|
|
C "github.com/Dreamacro/clash/constant"
|
|
P "github.com/Dreamacro/clash/constant/provider"
|
|
"github.com/Dreamacro/clash/rule/common"
|
|
)
|
|
|
|
type RuleSet struct {
|
|
*common.Base
|
|
ruleProviderName string
|
|
adapter string
|
|
ruleProvider P.RuleProvider
|
|
}
|
|
|
|
func (rs *RuleSet) ShouldFindProcess() bool {
|
|
return false
|
|
}
|
|
|
|
func (rs *RuleSet) RuleType() C.RuleType {
|
|
return C.RuleSet
|
|
}
|
|
|
|
func (rs *RuleSet) Match(metadata *C.Metadata) bool {
|
|
return rs.getProviders().Match(metadata)
|
|
}
|
|
|
|
func (rs *RuleSet) Adapter() string {
|
|
return rs.adapter
|
|
}
|
|
|
|
func (rs *RuleSet) Payload() string {
|
|
return rs.getProviders().Name()
|
|
}
|
|
|
|
func (rs *RuleSet) ShouldResolveIP() bool {
|
|
return rs.getProviders().ShouldResolveIP()
|
|
}
|
|
func (rs *RuleSet) getProviders() P.RuleProvider {
|
|
if rs.ruleProvider == nil {
|
|
rp := RuleProviders()[rs.ruleProviderName]
|
|
rs.ruleProvider = rp
|
|
}
|
|
|
|
return rs.ruleProvider
|
|
}
|
|
|
|
func NewRuleSet(ruleProviderName string, adapter string) (*RuleSet, error) {
|
|
rp, ok := RuleProviders()[ruleProviderName]
|
|
if !ok {
|
|
return nil, fmt.Errorf("rule set %s not found", ruleProviderName)
|
|
}
|
|
return &RuleSet{
|
|
Base: &common.Base{},
|
|
ruleProviderName: ruleProviderName,
|
|
adapter: adapter,
|
|
ruleProvider: rp,
|
|
}, nil
|
|
}
|