Replace "." characters with "_" when parsing environment variables

This brings viper in line with other configuration parsing libraries
and in line with what I would anticipate are the expectations of most
programms.
This commit is contained in:
Joe Buck 2016-02-18 21:48:15 -08:00
parent e8036e1a24
commit 8b2b4b8675

View file

@ -305,6 +305,10 @@ func (v *Viper) getEnv(key string) string {
if v.envKeyReplacer != nil { if v.envKeyReplacer != nil {
key = v.envKeyReplacer.Replace(key) key = v.envKeyReplacer.Replace(key)
} }
// Replace dots with underscores, since that is the sensible mapping
// for environment variables. The -1 means replace all insstances of "." with "_"
key = strings.Replace(key, ".", "_", -1)
return os.Getenv(key) return os.Getenv(key)
} }