diff --git a/config/config.go b/config/config.go index 8ba2976..7599ae1 100644 --- a/config/config.go +++ b/config/config.go @@ -2,7 +2,8 @@ package config import ( "fmt" - "github.com/mcuadros/go-defaults" + "github.com/creasty/defaults" + "github.com/pkg/errors" "go.uber.org/zap" "gopkg.in/yaml.v2" "io/ioutil" @@ -189,8 +190,6 @@ func (c *Configuration) SetDefaults() { Sftp: &SftpConfiguration{}, } - defaults.SetDefaults(c.System.Sftp) - // By default the internal webserver should bind to all interfaces and // be served on port 8080. c.Api = &ApiConfiguration{ @@ -222,9 +221,10 @@ func (c *Configuration) SetDefaults() { Interfaces: &dockerNetworkInterfaces{}, }, } - defaults.SetDefaults(c.Docker) - defaults.SetDefaults(c.Docker.Network) - defaults.SetDefaults(c.Docker.Network.Interfaces) + + if err := defaults.Set(c); err != nil { + zap.S().Warnw("error setting defaults for configuration", zap.Error(errors.WithStack(err))) + } } // Reads the configuration from the provided file and returns the configuration diff --git a/go.mod b/go.mod index 3fc8ff8..2e8c192 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,6 @@ require ( github.com/imdario/mergo v0.3.8 github.com/julienschmidt/httprouter v1.2.0 github.com/magiconair/properties v1.8.1 - github.com/mcuadros/go-defaults v1.1.0 github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee github.com/onsi/ginkgo v1.8.0 // indirect diff --git a/go.sum b/go.sum index 874e599..27058d3 100644 --- a/go.sum +++ b/go.sum @@ -74,8 +74,6 @@ github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE= github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mcuadros/go-defaults v1.1.0 h1:K0LgSNfsSUrbEHR7HgfZpOHVWYsPnYh/dKTA7pGeZ/I= -github.com/mcuadros/go-defaults v1.1.0/go.mod h1:vl9cJiNIIHISQeboDhZBUCiCOa3GkeioLe3Y95NXF6Y= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee h1:IquUs3fIykn10zWDIyddanhpTqBvAHMaPnFhQuyYw5U= diff --git a/installer/installer.go b/installer/installer.go index 9704ef6..0b9ec2f 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -30,7 +30,7 @@ func New(data []byte) (*Installer, error) { Uuid: getString(data, "uuid"), Suspended: false, State: server.ProcessOfflineState, - Invocation: "", + Invocation: getString(data, "invocation"), EnvVars: make(map[string]string), Build: server.BuildSettings{ MemoryLimit: getInt(data, "build", "memory"), diff --git a/server/server.go b/server/server.go index 7d0feb8..282f68b 100644 --- a/server/server.go +++ b/server/server.go @@ -2,7 +2,7 @@ package server import ( "fmt" - "github.com/mcuadros/go-defaults" + "github.com/creasty/defaults" "github.com/patrickmn/go-cache" "github.com/pkg/errors" "github.com/pterodactyl/wings/api" @@ -211,9 +211,8 @@ func (s *Server) Init() { func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, error) { s := new(Server) - defaults.SetDefaults(s) - s.CrashDetection = CrashDetection{ - Enabled: true, + if err := defaults.Set(s); err != nil { + return nil, err } s.Init() diff --git a/server/update.go b/server/update.go index f35cdbc..121b834 100644 --- a/server/update.go +++ b/server/update.go @@ -3,6 +3,7 @@ package server import ( "encoding/json" "github.com/buger/jsonparser" + "github.com/creasty/defaults" "github.com/imdario/mergo" "github.com/pkg/errors" "go.uber.org/zap" @@ -29,6 +30,11 @@ func (s *Server) UpdateDataStructure(data []byte) error { return errors.New("attempting to merge a data stack with an invalid UUID") } + // Set the default values in the interface that we unmarshaled into. + if err := defaults.Set(&src); err != nil { + return err + } + // Merge the new data object that we have received with the existing server data object // and then save it to the disk so it is persistent. if err := mergo.Merge(s, src, mergo.WithOverride); err != nil {