From 009b985c492123697a25aa247669042dbe8b0d6a Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 27 Oct 2018 12:57:56 +0800 Subject: [PATCH] Fix: weak type proxy name --- config/config.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/config/config.go b/config/config.go index 40e27c3c..ff784fef 100644 --- a/config/config.go +++ b/config/config.go @@ -250,14 +250,10 @@ func (c *Config) parseProxies(cfg *RawConfig) error { // parse proxy for idx, mapping := range proxiesConfig { proxyType, existType := mapping["type"].(string) - proxyName, existName := mapping["name"].(string) - if !existType && existName { - return fmt.Errorf("Proxy %d missing type or name", idx) + if !existType { + return fmt.Errorf("Proxy %d missing type", idx) } - if _, exist := proxies[proxyName]; exist { - return fmt.Errorf("Proxy %s is the duplicate name", proxyName) - } var proxy C.Proxy var err error switch proxyType { @@ -285,10 +281,15 @@ func (c *Config) parseProxies(cfg *RawConfig) error { default: return fmt.Errorf("Unsupport proxy type: %s", proxyType) } + if err != nil { - return fmt.Errorf("Proxy %s: %s", proxyName, err.Error()) + return fmt.Errorf("Proxy [%d]: %s", idx, err.Error()) } - proxies[proxyName] = proxy + + if _, exist := proxies[proxy.Name()]; exist { + return fmt.Errorf("Proxy %s is the duplicate name", proxy.Name()) + } + proxies[proxy.Name()] = proxy } // parse proxy group