aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/config
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-11-16 10:06:03 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-11-16 10:10:12 +0100
commit447a290a8c920f719f82e863277a645df65e1a43 (patch)
treec0c6c7e3ce83bd9d0cac986d378d6eef8dd2c057 /pkg/config
parent4f3b40072c43699f947a4111040f22a0a9a5a2e9 (diff)
pkg/config: provide SaveData function
Parallel to LoadFile/LoadData.
Diffstat (limited to 'pkg/config')
-rw-r--r--pkg/config/config.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index c1a761e18..b80e03b3f 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -35,13 +35,17 @@ func LoadData(data []byte, cfg interface{}) error {
}
func SaveFile(filename string, cfg interface{}) error {
- data, err := json.MarshalIndent(cfg, "", "\t")
+ data, err := SaveData(cfg)
if err != nil {
return err
}
return osutil.WriteFile(filename, data)
}
+func SaveData(cfg interface{}) ([]byte, error) {
+ return json.MarshalIndent(cfg, "", "\t")
+}
+
func checkUnknownFields(data []byte, typ reflect.Type) error {
if typ.Kind() != reflect.Ptr || typ.Elem().Kind() != reflect.Struct {
return fmt.Errorf("config type is not pointer to struct")