aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/config
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-06-19 16:34:59 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-06-19 16:34:59 +0200
commit261cdc2564653b62f966466332e5d145364b4073 (patch)
tree703f19e29ab6151925fbdda7b50533fcc0341235 /pkg/config
parent98877a11dd1ab9e9570bfc7552140ccec8b9d326 (diff)
pkg/config: add SaveFile function
Diffstat (limited to 'pkg/config')
-rw-r--r--pkg/config/config.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index b31399713..fc77d2496 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -32,6 +32,14 @@ func LoadData(data []byte, cfg interface{}) error {
return nil
}
+func SaveFile(filename string, cfg interface{}) error {
+ data, err := json.MarshalIndent(cfg, "", "\t")
+ if err != nil {
+ return err
+ }
+ return ioutil.WriteFile(filename, data, 0600)
+}
+
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")