config: fix gob encode/decode for raw config and keys
This commit is contained in:
parent
941e27b9f3
commit
fa05b165ad
|
@ -153,11 +153,15 @@ func (r *RawConfig) UnknownKeys() []string {
|
||||||
|
|
||||||
// See GobEncode
|
// See GobEncode
|
||||||
func (r *RawConfig) GobDecode(b []byte) error {
|
func (r *RawConfig) GobDecode(b []byte) error {
|
||||||
err := gob.NewDecoder(bytes.NewReader(b)).Decode(&r.Raw)
|
var data gobRawConfig
|
||||||
|
err := gob.NewDecoder(bytes.NewReader(b)).Decode(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.Key = data.Key
|
||||||
|
r.Raw = data.Raw
|
||||||
|
|
||||||
return r.init()
|
return r.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,10 +170,20 @@ func (r *RawConfig) GobDecode(b []byte) error {
|
||||||
// tree of interpolated variables is recomputed on decode, since it is
|
// tree of interpolated variables is recomputed on decode, since it is
|
||||||
// referentially transparent.
|
// referentially transparent.
|
||||||
func (r *RawConfig) GobEncode() ([]byte, error) {
|
func (r *RawConfig) GobEncode() ([]byte, error) {
|
||||||
|
data := gobRawConfig{
|
||||||
|
Key: r.Key,
|
||||||
|
Raw: r.Raw,
|
||||||
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := gob.NewEncoder(&buf).Encode(r.Raw); err != nil {
|
if err := gob.NewEncoder(&buf).Encode(data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type gobRawConfig struct {
|
||||||
|
Key string
|
||||||
|
Raw map[string]interface{}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue