mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
style: rule provider strategy
This commit is contained in:
parent
5e55d6b08f
commit
bf55428954
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"github.com/Dreamacro/clash/log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type classicalStrategy struct {
|
||||
|
@ -52,6 +53,19 @@ func (c *classicalStrategy) OnUpdate(rules []string) {
|
|||
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 {
|
||||
return &classicalStrategy{rules: []C.Rule{}, parse: func(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) {
|
||||
switch tp {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"github.com/Dreamacro/clash/component/trie"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"github.com/Dreamacro/clash/log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type domainStrategy struct {
|
||||
|
@ -40,19 +39,6 @@ func (d *domainStrategy) OnUpdate(rules []string) {
|
|||
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 {
|
||||
return &domainStrategy{}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user