mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +00:00
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:
parent
e8036e1a24
commit
8b2b4b8675
1 changed files with 4 additions and 0 deletions
4
viper.go
4
viper.go
|
@ -305,6 +305,10 @@ func (v *Viper) getEnv(key string) string {
|
|||
if v.envKeyReplacer != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue