MCPcopy
hub / github.com/spf13/viper / getEnv

Method getEnv

viper.go:442–450  ·  view source on GitHub ↗

TODO: should getEnv logic be moved into find(). Can generalize the use of rewriting keys many things, Ex: Get('someKey') -> some_key (camel case to snake case for JSON keys perhaps) getEnv is a wrapper around os.Getenv which replaces characters in the original key. This allows env vars which have di

(key string)

Source from the content-addressed store, hash-verified

440// key. This allows env vars which have different keys than the config object
441// keys.
442func (v *Viper) getEnv(key string) (string, bool) {
443 if v.envKeyReplacer != nil {
444 key = v.envKeyReplacer.Replace(key)
445 }
446
447 val, ok := os.LookupEnv(key)
448
449 return val, ok && (v.allowEmptyEnv || val != "")
450}
451
452// ConfigFileUsed returns the file used to populate the config registry.
453func ConfigFileUsed() string { return v.ConfigFileUsed() }

Callers 2

findMethod · 0.95

Calls 1

ReplaceMethod · 0.80

Tested by

no test coverage detected