Skip to content

Commit

Permalink
Fix: should keep the original order of proxy groups (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
comzyh authored and Dreamacro committed Aug 28, 2019
1 parent e34090c commit 0d51877
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
22 changes: 16 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}
Expand Down
3 changes: 0 additions & 3 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0d51877

Please sign in to comment.