fix: count error
This commit is contained in:
parent
7421c5f70a
commit
3a136cce56
3 changed files with 9 additions and 3 deletions
|
@ -32,6 +32,7 @@ func (c *classicalStrategy) ShouldResolveIP() bool {
|
|||
func (c *classicalStrategy) OnUpdate(rules []string) {
|
||||
var classicalRules []C.Rule
|
||||
shouldResolveIP := false
|
||||
count := 0
|
||||
for _, rawRule := range rules {
|
||||
ruleType, rule, params := ruleParse(rawRule)
|
||||
r, err := parseRule(ruleType, rule, "", params)
|
||||
|
@ -43,11 +44,12 @@ func (c *classicalStrategy) OnUpdate(rules []string) {
|
|||
}
|
||||
|
||||
classicalRules = append(classicalRules, r)
|
||||
c.count++
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
c.rules = classicalRules
|
||||
c.count = count
|
||||
}
|
||||
|
||||
func NewClassicalStrategy() *classicalStrategy {
|
||||
|
|
|
@ -27,16 +27,18 @@ func (d *domainStrategy) ShouldResolveIP() bool {
|
|||
|
||||
func (d *domainStrategy) OnUpdate(rules []string) {
|
||||
domainTrie := trie.New[bool]()
|
||||
count := 0
|
||||
for _, rule := range rules {
|
||||
err := domainTrie.Insert(rule, true)
|
||||
if err != nil {
|
||||
log.Warnln("invalid domain:[%s]", rule)
|
||||
} else {
|
||||
d.count++
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
d.domainRules = domainTrie
|
||||
d.count = count
|
||||
}
|
||||
|
||||
func ruleParse(ruleRaw string) (string, string, []string) {
|
||||
|
|
|
@ -26,16 +26,18 @@ func (i *ipcidrStrategy) ShouldResolveIP() bool {
|
|||
|
||||
func (i *ipcidrStrategy) OnUpdate(rules []string) {
|
||||
ipCidrTrie := trie.NewIpCidrTrie()
|
||||
count := 0
|
||||
for _, rule := range rules {
|
||||
err := ipCidrTrie.AddIpCidrForString(rule)
|
||||
if err != nil {
|
||||
log.Warnln("invalid Ipcidr:[%s]", rule)
|
||||
} else {
|
||||
i.count++
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
i.trie = ipCidrTrie
|
||||
i.count = count
|
||||
i.shouldResolveIP = i.count > 0
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue