Procházet zdrojové kódy

config: Re-add interface keyword to keep compatibility

This re-adds an `interface` keyword in the configuration to keep
compatibility with existing configuration files. The behaviour is
emulated in terms of the `listen` keyword.
Both cannot be used together, but since listen wasn't an accepted
keyword previously, users are expected to remove the old one when they
add the new one

Signed-off-by: Anatole Denis <anatole@unverle.fr>
Anatole Denis před 5 roky
rodič
revize
227f60d8eb
1 změnil soubory, kde provedl 9 přidání a 0 odebrání
  1. 9 0
      config/config.go

+ 9 - 0
config/config.go

@@ -294,6 +294,15 @@ func (c *Config) parseListen(ver protocolVersion) ([]net.UDPAddr, error) {
 	}
 
 	listen := c.v.Get(fmt.Sprintf("server%d.listen", ver))
+
+	// Provide an emulation of the old keyword "interface" to avoid breaking config files
+	if iface := c.v.Get(fmt.Sprintf("server%d.interface", ver)); iface != nil && listen != nil {
+		return nil, ConfigErrorFromString("interface is a deprecated alias for listen, " +
+			"both cannot be used at the same time. Choose one and remove the other.")
+	} else if iface != nil {
+		listen = "%" + cast.ToString(iface)
+	}
+
 	if listen == nil {
 		return defaultListen(ver)
 	}