Added new method for getting Defaults values from config.

In some cases, app needs to print default values for user.
This PR add new `GetDefaults` method.
This feature was mentioned in #376
This commit is contained in:
Kamil Wargula 2017-10-20 13:45:18 +02:00
parent 8ef37cbca7
commit 4557438166
2 changed files with 14 additions and 0 deletions

View file

@ -80,6 +80,14 @@ viper.SetDefault("LayoutDir", "layouts")
viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "categories"}) viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "categories"})
``` ```
Optionally you can get all Defaults values for config.
example:
```go
viper.GetDefaults()
```
### Reading Config Files ### Reading Config Files
Viper requires minimal configuration so it knows where to look for config files. Viper requires minimal configuration so it knows where to look for config files.

View file

@ -1087,6 +1087,12 @@ func (v *Viper) SetDefault(key string, value interface{}) {
deepestMap[lastKey] = value deepestMap[lastKey] = value
} }
// GetDefaults gets the all defaults values
func GetDefaults() map[string]interface{} { return v.GetDefaults() }
func (v *Viper) GetDefaults() map[string]interface{} {
return v.defaults
}
// Set sets the value for the key in the override regiser. // Set sets the value for the key in the override regiser.
// Set is case-insensitive for a key. // Set is case-insensitive for a key.
// Will be used instead of values obtained via // Will be used instead of values obtained via