From 11ae2b93920f8a790b92bc1fc39d64e827290f6a Mon Sep 17 00:00:00 2001 From: g3rk6 Date: Sun, 10 Jan 2016 21:59:10 -0500 Subject: [PATCH] Added method to write into YAML file. --- viper.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/viper.go b/viper.go index 7c542af..9a2ace3 100644 --- a/viper.go +++ b/viper.go @@ -40,6 +40,7 @@ import ( jww "github.com/spf13/jwalterweatherman" "github.com/spf13/pflag" "gopkg.in/fsnotify.v1" + "gopkg.in/yaml.v2" ) var v *Viper @@ -909,6 +910,14 @@ func (v *Viper) SaveConfig() error { jww.FATAL.Println("Panic while encoding into TOML format.") } w.Flush() + + case "yaml", "yml": + + b, err := yaml.Marshal(v.AllSettings()) + if err != nil { + jww.FATAL.Println("Panic while encoding into YAML format.") + } + f.WriteString(string(b)) } return nil