fix pointer ref of updateJSONConfigs

jsonConfigs.getSection() returned a value when it needed to
return a pointer to the jsonSection fields inside the struct.

Even though the jsonSection type is a map, therefore on the heap,
returning it as a value (non-pointer) resulted in it being
disassociated with the jsonConfigs overarching struct.

License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
This commit is contained in:
Adrian Lanzafame 2019-02-06 09:48:25 +10:00
parent 5a7ee1d310
commit 237ede5fce
No known key found for this signature in database
GPG Key ID: 87E40C5D62EAE192

View File

@ -178,26 +178,26 @@ type jsonConfig struct {
Observations jsonSection `json:"observations,omitempty"` Observations jsonSection `json:"observations,omitempty"`
} }
func (jcfg *jsonConfig) getSection(i SectionType) jsonSection { func (jcfg *jsonConfig) getSection(i SectionType) *jsonSection {
switch i { switch i {
case Consensus: case Consensus:
return jcfg.Consensus return &jcfg.Consensus
case API: case API:
return jcfg.API return &jcfg.API
case IPFSConn: case IPFSConn:
return jcfg.IPFSConn return &jcfg.IPFSConn
case State: case State:
return jcfg.State return &jcfg.State
case PinTracker: case PinTracker:
return jcfg.PinTracker return &jcfg.PinTracker
case Monitor: case Monitor:
return jcfg.Monitor return &jcfg.Monitor
case Allocator: case Allocator:
return jcfg.Allocator return &jcfg.Allocator
case Informer: case Informer:
return jcfg.Informer return &jcfg.Informer
case Observations: case Observations:
return jcfg.Observations return &jcfg.Observations
default: default:
return nil return nil
} }
@ -356,7 +356,7 @@ func (cfg *Manager) LoadJSON(bs []byte) error {
if t == Cluster { if t == Cluster {
continue continue
} }
err := loadSectionJSON(sections[t], jcfg.getSection(t)) err := loadSectionJSON(sections[t], *jcfg.getSection(t))
if err != nil { if err != nil {
return err return err
} }
@ -445,7 +445,7 @@ func (cfg *Manager) ToJSON() ([]byte, error) {
continue continue
} }
jsection := jcfg.getSection(t) jsection := jcfg.getSection(t)
err := updateJSONConfigs(cfg.sections[t], &jsection) err := updateJSONConfigs(cfg.sections[t], jsection)
if err != nil { if err != nil {
return nil, err return nil, err
} }