mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +00:00
Added method to write into YAML file.
This commit is contained in:
parent
d5c009456e
commit
11ae2b9392
1 changed files with 9 additions and 0 deletions
9
viper.go
9
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
|
||||
|
|
Loading…
Reference in a new issue