Correctly handle updating server data
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user