Correctly handle updating server data

This commit is contained in:
Dane Everitt
2019-12-21 21:02:02 -08:00
parent d583c1d53e
commit 189289ad5f
6 changed files with 16 additions and 14 deletions

View File

@@ -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()

View File

@@ -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 {