style: rule provider strategy

This commit is contained in:
Skyxim 2022-06-18 17:53:40 +08:00
parent 5e55d6b08f
commit bf55428954
2 changed files with 14 additions and 14 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
"strings"
) )
type classicalStrategy struct { type classicalStrategy struct {
@ -52,6 +53,19 @@ func (c *classicalStrategy) OnUpdate(rules []string) {
c.count = len(classicalRules) c.count = len(classicalRules)
} }
func ruleParse(ruleRaw string) (string, string, []string) {
item := strings.Split(ruleRaw, ",")
if len(item) == 1 {
return "", item[0], nil
} else if len(item) == 2 {
return item[0], item[1], nil
} else if len(item) > 2 {
return item[0], item[1], item[2:]
}
return "", "", nil
}
func NewClassicalStrategy(parse func(tp, payload, target string, params []string) (parsed C.Rule, parseErr error)) *classicalStrategy { 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) { return &classicalStrategy{rules: []C.Rule{}, parse: func(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) {
switch tp { switch tp {

View file

@ -4,7 +4,6 @@ import (
"github.com/Dreamacro/clash/component/trie" "github.com/Dreamacro/clash/component/trie"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
"strings"
) )
type domainStrategy struct { type domainStrategy struct {
@ -40,19 +39,6 @@ func (d *domainStrategy) OnUpdate(rules []string) {
d.count = count d.count = count
} }
func ruleParse(ruleRaw string) (string, string, []string) {
item := strings.Split(ruleRaw, ",")
if len(item) == 1 {
return "", item[0], nil
} else if len(item) == 2 {
return item[0], item[1], nil
} else if len(item) > 2 {
return item[0], item[1], item[2:]
}
return "", "", nil
}
func NewDomainStrategy() *domainStrategy { func NewDomainStrategy() *domainStrategy {
return &domainStrategy{} return &domainStrategy{}
} }