mirror of
https://github.com/spf13/viper
synced 2024-11-20 03:47:05 +00:00
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:
parent
8ef37cbca7
commit
4557438166
2 changed files with 14 additions and 0 deletions
|
@ -80,6 +80,14 @@ viper.SetDefault("LayoutDir", "layouts")
|
|||
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
|
||||
|
||||
Viper requires minimal configuration so it knows where to look for config files.
|
||||
|
|
6
viper.go
6
viper.go
|
@ -1087,6 +1087,12 @@ func (v *Viper) SetDefault(key string, value interface{}) {
|
|||
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 is case-insensitive for a key.
|
||||
// Will be used instead of values obtained via
|
||||
|
|
Loading…
Reference in a new issue