From b538aa6ca2f0e736b9544f011ddd8a5056da2ae2 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 8 Dec 2023 09:26:24 +0800 Subject: [PATCH] chore: code cleanup --- dns/resolver.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dns/resolver.go b/dns/resolver.go index 67e6fbc2..47ea78d8 100644 --- a/dns/resolver.go +++ b/dns/resolver.go @@ -483,12 +483,15 @@ func NewResolver(config Config) *Resolver { r.policy = make([]dnsPolicy, 0) var triePolicy *trie.DomainTrie[[]dnsClient] - insertTriePolicy := func() { + insertPolicy := func(policy dnsPolicy) { if triePolicy != nil { triePolicy.Optimize() r.policy = append(r.policy, domainTriePolicy{triePolicy}) triePolicy = nil } + if policy != nil { + r.policy = append(r.policy, policy) + } } for pair := config.Policy.Oldest(); pair != nil; pair = pair.Next() { @@ -501,8 +504,7 @@ func NewResolver(config Config) *Resolver { case "rule-set": if p, ok := config.RuleProviders[key]; ok { log.Debugln("Adding rule-set policy: %s ", key) - insertTriePolicy() - r.policy = append(r.policy, domainSetPolicy{ + insertPolicy(domainSetPolicy{ domainSetProvider: p, dnsClients: cacheTransform(nameserver), }) @@ -522,8 +524,7 @@ func NewResolver(config Config) *Resolver { log.Warnln("adding geosite policy %s error: %s", key, err) continue } - insertTriePolicy() - r.policy = append(r.policy, geositePolicy{ + insertPolicy(geositePolicy{ matcher: matcher, inverse: inverse, dnsClients: cacheTransform(nameserver), @@ -536,7 +537,7 @@ func NewResolver(config Config) *Resolver { } _ = triePolicy.Insert(domain, cacheTransform(nameserver)) } - insertTriePolicy() + insertPolicy(nil) } fallbackIPFilters := []fallbackIPFilter{}