From 45574381669c22dd201029dd94d01f1090602a83 Mon Sep 17 00:00:00 2001 From: Kamil Wargula Date: Fri, 20 Oct 2017 13:45:18 +0200 Subject: [PATCH] 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 --- README.md | 8 ++++++++ viper.go | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 64bf474..8499efe 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/viper.go b/viper.go index 963861a..eb2b91f 100644 --- a/viper.go +++ b/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