spf13 / viper

Go configuration with fangs
MIT License
27.26k stars 2.02k forks source link

Enable Marshalling to string #529

Open bricef opened 6 years ago

bricef commented 6 years ago

I'd like to marshall the config to a string (or to a file-like object) so that it can be written to stdout or used in some other way.

This isn't currently allowed as the Marshal functions are private.

bricef commented 6 years ago

This can be solved by using the marshalling the entire config manually. for example:

c := viper.AllSettings()
bs, err := yaml.Marshal(c)
if err != nil {
    // handle marshalling error
}
fmt.Print(string(bs))