From 0d51877fcdab1392c4dedfce0fabfb494998d6cb Mon Sep 17 00:00:00 2001 From: Comzyh Date: Wed, 28 Aug 2019 23:44:32 +0800 Subject: [PATCH] Fix: should keep the original order of proxy groups (#284) --- config/config.go | 22 ++++++++++++++++------ config/utils.go | 3 --- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/config/config.go b/config/config.go index 942ee87617..080a6e499b 100644 --- a/config/config.go +++ b/config/config.go @@ -292,15 +292,26 @@ func parseProxies(cfg *rawConfig) (map[string]C.Proxy, error) { proxyList = append(proxyList, proxy.Name()) } - // parse proxy group + // keep the origional order of ProxyGroups in config file + for idx, mapping := range groupsConfig { + groupName, existName := mapping["name"].(string) + if !existName { + return nil, fmt.Errorf("ProxyGroup %d: missing name", idx) + } + proxyList = append(proxyList, groupName) + } + + // check if any loop exists and sort the ProxyGroups if err := proxyGroupsDagSort(groupsConfig); err != nil { return nil, err } - for idx, mapping := range groupsConfig { + + // parse proxy group + for _, mapping := range groupsConfig { groupType, existType := mapping["type"].(string) - groupName, existName := mapping["name"].(string) - if !(existType && existName) { - return nil, fmt.Errorf("ProxyGroup %d: missing type or name", idx) + groupName, _ := mapping["name"].(string) + if !existType { + return nil, fmt.Errorf("ProxyGroup %s: missing type", groupName) } if _, exist := proxies[groupName]; exist { @@ -364,7 +375,6 @@ func parseProxies(cfg *rawConfig) (map[string]C.Proxy, error) { return nil, fmt.Errorf("Proxy %s: %s", groupName, err.Error()) } proxies[groupName] = adapters.NewProxy(group) - proxyList = append(proxyList, groupName) } ps := []C.Proxy{} diff --git a/config/utils.go b/config/utils.go index 7c6b69f34b..f2832f563a 100644 --- a/config/utils.go +++ b/config/utils.go @@ -55,9 +55,6 @@ func proxyGroupsDagSort(groupsConfig []map[string]interface{}) error { // Step 1.1 build dependency graph for idx, mapping := range groupsConfig { - // record original order in config file. - // this field can be used determinate the display order in FrontEnd. - mapping["configIdx"] = idx groupName, existName := mapping["name"].(string) if !existName { return fmt.Errorf("ProxyGroup %d: missing name", idx)