From 3611c6c1c4079669bc121acff270fe8ee51406b0 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/viper.go b/viper.go index 9c45bc1..8625687 100644 --- a/viper.go +++ b/viper.go @@ -33,6 +33,8 @@ import ( "strings" "time" + yaml "gopkg.in/yaml.v2" + "github.com/BurntSushi/toml" "github.com/fsnotify/fsnotify" "github.com/mitchellh/mapstructure" @@ -1102,6 +1104,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