diff options
Diffstat (limited to 'vendor/github.com/spf13/viper/viper.go')
-rw-r--r-- | vendor/github.com/spf13/viper/viper.go | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/vendor/github.com/spf13/viper/viper.go b/vendor/github.com/spf13/viper/viper.go index ad8a03729..b9e165695 100644 --- a/vendor/github.com/spf13/viper/viper.go +++ b/vendor/github.com/spf13/viper/viper.go @@ -1675,6 +1675,26 @@ func (v *Viper) AllSettings() map[string]interface{} { return m } +// EnvSettings returns a map[string]interface{} containing all settings set +// through environment variables. +func EnvSettings() map[string]interface{} { return v.EnvSettings() } +func (v *Viper) EnvSettings() map[string]interface{} { + m := map[string]interface{}{} + // start from the list of keys, and construct the map one value at a time + for _, k := range v.AllKeys() { + value := v.getEnv(v.mergeWithEnvPrefix(k)) + if value == "" { + continue + } + path := strings.Split(k, v.keyDelim) + lastKey := strings.ToLower(path[len(path)-1]) + deepestMap := deepSearch(m, path[0:len(path)-1]) + // set innermost value + deepestMap[lastKey] = true + } + return m +} + // SetFs sets the filesystem to use to read configuration. func SetFs(fs afero.Fs) { v.SetFs(fs) } func (v *Viper) SetFs(fs afero.Fs) { @@ -1720,18 +1740,14 @@ func (v *Viper) getConfigType() string { } func (v *Viper) getConfigFile() (string, error) { - // if explicitly set, then use it - if v.configFile != "" { - return v.configFile, nil - } - - cf, err := v.findConfigFile() - if err != nil { - return "", err + if v.configFile == "" { + cf, err := v.findConfigFile() + if err != nil { + return "", err + } + v.configFile = cf } - - v.configFile = cf - return v.getConfigFile() + return v.configFile, nil } func (v *Viper) searchInPath(in string) (filename string) { |