mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-17 20:53:18 +08:00
♻️ Refactor code
🔥 Remove update detection
This commit is contained in:
50
common/rule.go
Normal file
50
common/rule.go
Normal file
@ -0,0 +1,50 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sub2clash/model"
|
||||
)
|
||||
|
||||
func PrependRuleProvider(
|
||||
sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
|
||||
) {
|
||||
if sub.RuleProviders == nil {
|
||||
sub.RuleProviders = make(map[string]model.RuleProvider)
|
||||
}
|
||||
sub.RuleProviders[providerName] = provider
|
||||
PrependRules(
|
||||
sub,
|
||||
fmt.Sprintf("RULE-SET,%s,%s", providerName, group),
|
||||
)
|
||||
}
|
||||
|
||||
func AppenddRuleProvider(
|
||||
sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
|
||||
) {
|
||||
if sub.RuleProviders == nil {
|
||||
sub.RuleProviders = make(map[string]model.RuleProvider)
|
||||
}
|
||||
sub.RuleProviders[providerName] = provider
|
||||
AppendRules(sub, fmt.Sprintf("RULE-SET,%s,%s", providerName, group))
|
||||
}
|
||||
|
||||
func PrependRules(sub *model.Subscription, rules ...string) {
|
||||
if sub.Rules == nil {
|
||||
sub.Rules = make([]string, 0)
|
||||
}
|
||||
sub.Rules = append(rules, sub.Rules...)
|
||||
}
|
||||
|
||||
func AppendRules(sub *model.Subscription, rules ...string) {
|
||||
if sub.Rules == nil {
|
||||
sub.Rules = make([]string, 0)
|
||||
}
|
||||
matchRule := sub.Rules[len(sub.Rules)-1]
|
||||
if strings.Contains(matchRule, "MATCH") {
|
||||
sub.Rules = append(sub.Rules[:len(sub.Rules)-1], rules...)
|
||||
sub.Rules = append(sub.Rules, matchRule)
|
||||
return
|
||||
}
|
||||
sub.Rules = append(sub.Rules, rules...)
|
||||
}
|
Reference in New Issue
Block a user