diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-28 10:37:13 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-28 10:37:13 +0100 |
| commit | a5b147b38ebdd8d50220037f5937fe2b07f07c78 (patch) | |
| tree | 97eea9cd0c7d2d3335476a01c4a041c6ac864e01 /internal | |
| parent | 15cb268440b54bcbdcae9d64e1d5d083e99d74e7 (diff) | |
Config: Add a version field
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/config.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index ae023ff..239e456 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -20,6 +20,10 @@ type Config struct { Name string } +type ConfigFormat struct { + Data interface{} `json:"v1"` +} + // Init initializes the configuration using the provided directory and name. func (c *Config) Init(directory string, name string) { c.Directory = directory @@ -37,7 +41,8 @@ func (c *Config) Save(readStruct interface{}) error { if err := util.EnsureDirectory(c.Directory); err != nil { return err } - cfg, err := json.Marshal(readStruct) + cf := &ConfigFormat{Data: readStruct} + cfg, err := json.Marshal(cf) if err != nil { return errors.WrapPrefix(err, "json.Marshal failed", 0) } @@ -54,7 +59,8 @@ func (c *Config) Load(writeStruct interface{}) error { if err != nil { return errors.WrapPrefix(err, "failed loading configuration", 0) } - if err = json.Unmarshal(bts, writeStruct); err != nil { + cf := ConfigFormat{Data: writeStruct} + if err = json.Unmarshal(bts, &cf); err != nil { return errors.WrapPrefix(err, "json.Unmarshal failed", 0) } return nil |
