cleanup: Use YAML parser to load JSON config

Issue #6
create-reload-action
Lukasz Janyst 4 years ago
parent 6fa70a8711
commit d006d4b20c
No known key found for this signature in database
GPG Key ID: 32DE641041F17A9A
  1. 15
      pkg/config/settings/kvs.go

@ -18,11 +18,11 @@
package settings
import (
"encoding/json"
"os"
"io/ioutil"
"strconv"
"sync"
"github.com/ghodss/yaml"
"github.com/sirupsen/logrus"
)
@ -39,7 +39,7 @@ func newKeyValueStore(path string) *keyValueStore {
lock: &sync.RWMutex{},
}
if err := p.load(); err != nil {
logrus.WithError(err).Warn("Cannot load preferences file, creating new one")
logrus.WithError(err).Warn("Cannot load preferences file, using defaults")
}
return p
}
@ -54,13 +54,16 @@ func (p *keyValueStore) load() error {
p.cache = map[string]string{}
f, err := os.Open(p.path)
data, err := ioutil.ReadFile(p.path)
if err != nil {
return err
}
defer f.Close() //nolint[errcheck]
return json.NewDecoder(f).Decode(&p.cache)
if len(data) == 0 {
return nil
}
return yaml.Unmarshal(data, &p.cache)
}
func (p *keyValueStore) setDefault(key, value string) {

Loading…
Cancel
Save