Explorar o código

config: Remove a layer of indirection in ServerConfig

It wasn't really necessary to hold pointers inside a slice (itself a
pointer to array) inside a struct with pointer-recever methods. It's
easier to understand and reason about like this

Signed-off-by: Anatole Denis <anatole@unverle.fr>
Anatole Denis %!s(int64=6) %!d(string=hai) anos
pai
achega
52c5f423c8
Modificáronse 2 ficheiros con 10 adicións e 10 borrados
  1. 8 8
      config/config.go
  2. 2 2
      server/serve.go

+ 8 - 8
config/config.go

@@ -41,8 +41,8 @@ func New() *Config {
 // ServerConfig holds a server configuration that is specific to either the
 // DHCPv6 server or the DHCPv4 server.
 type ServerConfig struct {
-	Addresses []*net.UDPAddr
-	Plugins   []*PluginConfig
+	Addresses []net.UDPAddr
+	Plugins   []PluginConfig
 }
 
 // PluginConfig holds the configuration of a plugin
@@ -83,8 +83,8 @@ func protoVersionCheck(v protocolVersion) error {
 	return nil
 }
 
-func parsePlugins(pluginList []interface{}) ([]*PluginConfig, error) {
-	plugins := make([]*PluginConfig, 0)
+func parsePlugins(pluginList []interface{}) ([]PluginConfig, error) {
+	plugins := make([]PluginConfig, 0, len(pluginList))
 	for idx, val := range pluginList {
 		conf := cast.ToStringMap(val)
 		if conf == nil {
@@ -105,7 +105,7 @@ func parsePlugins(pluginList []interface{}) ([]*PluginConfig, error) {
 			args = strings.Fields(cast.ToString(v))
 			break
 		}
-		plugins = append(plugins, &PluginConfig{Name: name, Args: args})
+		plugins = append(plugins, PluginConfig{Name: name, Args: args})
 	}
 	return plugins, nil
 }
@@ -188,7 +188,7 @@ func (c *Config) getListenAddress(addr string, ver protocolVersion) (*net.UDPAdd
 	return &listener, nil
 }
 
-func (c *Config) getPlugins(ver protocolVersion) ([]*PluginConfig, error) {
+func (c *Config) getPlugins(ver protocolVersion) ([]PluginConfig, error) {
 	if err := protoVersionCheck(ver); err != nil {
 		return nil, err
 	}
@@ -222,13 +222,13 @@ func (c *Config) parseConfig(ver protocolVersion) error {
 		addrs = []string{cast.ToString(listen)}
 	}
 
-	listeners := []*net.UDPAddr{}
+	listeners := []net.UDPAddr{}
 	for _, a := range addrs {
 		listenAddr, err := c.getListenAddress(a, ver)
 		if err != nil {
 			return err
 		}
-		listeners = append(listeners, listenAddr)
+		listeners = append(listeners, *listenAddr)
 	}
 
 	sc := ServerConfig{

+ 2 - 2
server/serve.go

@@ -126,7 +126,7 @@ func Start(config *config.Config) (*Servers, error) {
 		log.Println("Starting DHCPv6 server")
 		for _, addr := range config.Server6.Addresses {
 			var l6 *listener6
-			l6, err = listen6(addr)
+			l6, err = listen6(&addr)
 			if err != nil {
 				goto cleanup
 			}
@@ -142,7 +142,7 @@ func Start(config *config.Config) (*Servers, error) {
 		log.Println("Starting DHCPv4 server")
 		for _, addr := range config.Server4.Addresses {
 			var l4 *listener4
-			l4, err = listen4(addr)
+			l4, err = listen4(&addr)
 			if err != nil {
 				goto cleanup
 			}