mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
Add deep map logic to config Aliases
This commit is contained in:
parent
7a605a50e6
commit
552643cc82
1 changed files with 6 additions and 0 deletions
6
viper.go
6
viper.go
|
@ -1139,6 +1139,12 @@ func (v *Viper) registerAlias(alias string, key string) {
|
||||||
// if we alias something that exists in one of the maps to another
|
// if we alias something that exists in one of the maps to another
|
||||||
// name, we'll never be able to get that value using the original
|
// name, we'll never be able to get that value using the original
|
||||||
// name, so move the config value to the new realkey.
|
// name, so move the config value to the new realkey.
|
||||||
|
path := strings.Split(alias, v.keyDelim)
|
||||||
|
if val := v.searchMapWithPathPrefixes(v.config, path); val != nil {
|
||||||
|
parent := v.searchMapWithPathPrefixes(v.config, path[:len(path)-1])
|
||||||
|
delete(parent.(map[string]interface{}), path[len(path)-1])
|
||||||
|
v.config[key] = val
|
||||||
|
}
|
||||||
if val, ok := v.config[alias]; ok {
|
if val, ok := v.config[alias]; ok {
|
||||||
delete(v.config, alias)
|
delete(v.config, alias)
|
||||||
v.config[key] = val
|
v.config[key] = val
|
||||||
|
|
Loading…
Reference in a new issue