From 552643cc824341d5c53f671b967fc13143b8c01a Mon Sep 17 00:00:00 2001 From: Mitch Connors Date: Tue, 23 Apr 2019 17:09:22 -0700 Subject: [PATCH] Add deep map logic to config Aliases --- viper.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/viper.go b/viper.go index a3d37f8..8623b1f 100644 --- a/viper.go +++ b/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 // name, we'll never be able to get that value using the original // 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 { delete(v.config, alias) v.config[key] = val