refactor: clear linkname,reduce cycle dependencies,transport init geosite function

This commit is contained in:
Skyxim
2022-06-10 13:36:09 +08:00
parent 9a55213ddc
commit 130a3a261d
15 changed files with 203 additions and 149 deletions

View File

@@ -1,6 +1,7 @@
package provider
import (
"fmt"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
)
@@ -9,6 +10,7 @@ type classicalStrategy struct {
rules []C.Rule
count int
shouldResolveIP bool
parse func(tp, payload, target string, params []string) (parsed C.Rule, parseErr error)
}
func (c *classicalStrategy) Match(metadata *C.Metadata) bool {
@@ -34,7 +36,7 @@ func (c *classicalStrategy) OnUpdate(rules []string) {
shouldResolveIP := false
for _, rawRule := range rules {
ruleType, rule, params := ruleParse(rawRule)
r, err := parseRule(ruleType, rule, "", params)
r, err := c.parse(ruleType, rule, "", params)
if err != nil {
log.Warnln("parse rule error:[%s]", err.Error())
} else {
@@ -50,6 +52,13 @@ func (c *classicalStrategy) OnUpdate(rules []string) {
c.count = len(classicalRules)
}
func NewClassicalStrategy() *classicalStrategy {
return &classicalStrategy{rules: []C.Rule{}}
func NewClassicalStrategy(parse func(tp, payload, target string, params []string) (parsed C.Rule, parseErr error)) *classicalStrategy {
return &classicalStrategy{rules: []C.Rule{}, parse: func(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) {
switch tp {
case "MATCH":
return nil, fmt.Errorf("unsupported rule type on rule-set")
default:
return parse(tp, payload, target, params)
}
}}
}