| 1420 | } |
| 1421 | |
| 1422 | func (v *Viper) registerAlias(alias, key string) { |
| 1423 | alias = strings.ToLower(alias) |
| 1424 | if alias != key && alias != v.realKey(key) { |
| 1425 | _, exists := v.aliases[alias] |
| 1426 | |
| 1427 | if !exists { |
| 1428 | // if we alias something that exists in one of the maps to another |
| 1429 | // name, we'll never be able to get that value using the original |
| 1430 | // name, so move the config value to the new realkey. |
| 1431 | if val, ok := v.config[alias]; ok { |
| 1432 | delete(v.config, alias) |
| 1433 | v.config[key] = val |
| 1434 | } |
| 1435 | if val, ok := v.kvstore[alias]; ok { |
| 1436 | delete(v.kvstore, alias) |
| 1437 | v.kvstore[key] = val |
| 1438 | } |
| 1439 | if val, ok := v.defaults[alias]; ok { |
| 1440 | delete(v.defaults, alias) |
| 1441 | v.defaults[key] = val |
| 1442 | } |
| 1443 | if val, ok := v.override[alias]; ok { |
| 1444 | delete(v.override, alias) |
| 1445 | v.override[key] = val |
| 1446 | } |
| 1447 | v.aliases[alias] = key |
| 1448 | } |
| 1449 | } else { |
| 1450 | v.logger.Warn("creating circular reference alias", "alias", alias, "key", key, "real_key", v.realKey(key)) |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | func (v *Viper) realKey(key string) string { |
| 1455 | newkey, exists := v.aliases[key] |