mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
Added method to write into YAML file.
This commit is contained in:
parent
71d6b8c96f
commit
3611c6c1c4
1 changed files with 10 additions and 0 deletions
10
viper.go
10
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
|
||||
|
|
Loading…
Add table
Reference in a new issue