From f4251e58a5e933d1da1f0f9896085bd838388537 Mon Sep 17 00:00:00 2001 From: Larvan2 <78135608+Larvan2@users.noreply.github.com> Date: Tue, 14 Mar 2023 14:23:10 +0800 Subject: [PATCH] chore: clean up code --- config/config.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index dfcb772e..61222af7 100644 --- a/config/config.go +++ b/config/config.go @@ -989,30 +989,27 @@ func parseNameServerPolicy(nsPolicy map[string]any, preferH3 bool) (map[string][ re := regexp.MustCompile(`[a-zA-Z0-9\-]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?`) for k, v := range nsPolicy { - if strings.Contains(k, "geosite:") { - subkeys := strings.Split(k, ":") - subkeys = subkeys[1:] - subkeys = strings.Split(subkeys[0], ",") - //log.Infoln("subkeys:%+v", subkeys) - for _, subkey := range subkeys { - newKey := "geosite:" + subkey - //log.Infoln("newKey:%+v", newKey) - updatedPolicy[newKey] = v - } - } else if re.MatchString(k) { - subkeys := strings.Split(k, ",") - //log.Infoln("subkeys:%+v", subkeys) - for _, subkey := range subkeys { - updatedPolicy[subkey] = v + if strings.Contains(k, ",") { + if strings.Contains(k, "geosite:") { + subkeys := strings.Split(k, ":") + subkeys = subkeys[1:] + subkeys = strings.Split(subkeys[0], ",") + for _, subkey := range subkeys { + newKey := "geosite:" + subkey + updatedPolicy[newKey] = v + } + } else if re.MatchString(k) { + subkeys := strings.Split(k, ",") + for _, subkey := range subkeys { + updatedPolicy[subkey] = v + } } } else { updatedPolicy[k] = v } } - //log.Infoln("updatedPolicy:%+v", updatedPolicy) for domain, server := range updatedPolicy { - servers, err := utils.ToStringSlice(server) if err != nil { return nil, err