mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
Add support for toml
This commit is contained in:
parent
4fae23fe25
commit
c4b0efecc9
1 changed files with 15 additions and 9 deletions
24
util.go
24
util.go
|
@ -164,31 +164,37 @@ func userHomeDir() string {
|
|||
return os.Getenv("HOME")
|
||||
}
|
||||
|
||||
func marshalConfigWriter(out afero.File, c map[string]interface{}, configType string) error {
|
||||
func marshalConfigWriter(f afero.File, c map[string]interface{}, configType string) error {
|
||||
switch configType {
|
||||
case "json":
|
||||
b, err := json.MarshalIndent(v.AllSettings(), "", " ")
|
||||
if err != nil {
|
||||
return ConfigMarshalError{err}
|
||||
}
|
||||
_, err = out.WriteString(string(b))
|
||||
_, err = f.WriteString(string(b))
|
||||
if err != nil {
|
||||
return ConfigMarshalError{err}
|
||||
}
|
||||
|
||||
// case "toml":
|
||||
// w := bufio.NewWriter(out)
|
||||
// if err := toml.NewEncoder(w).Encode(v.AllSettings()); err != nil {
|
||||
// return ConfigMarshalError{err}
|
||||
// }
|
||||
// w.Flush()
|
||||
case "hcl":
|
||||
// TODO: How to convert map to hcl???
|
||||
|
||||
case "prop", "props", "properties":
|
||||
|
||||
case "toml":
|
||||
t := toml.TreeFromMap(v.AllSettings())
|
||||
s := t.String()
|
||||
_, err := f.WriteString(s)
|
||||
if err != nil {
|
||||
return ConfigMarshalError{err}
|
||||
}
|
||||
|
||||
case "yaml", "yml":
|
||||
b, err := yaml.Marshal(v.AllSettings())
|
||||
if err != nil {
|
||||
return ConfigMarshalError{err}
|
||||
}
|
||||
_, err = out.WriteString(string(b))
|
||||
_, err = f.WriteString(string(b))
|
||||
if err != nil {
|
||||
return ConfigMarshalError{err}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue