Fix case issue Viper vs Blackfriday config

There are still work to be done in the case department, but that will have to be another day.

Fixes #2581
See https://github.com/spf13/viper/issues/261
This commit is contained in:
Bjørn Erik Pedersen
2016-10-16 19:28:21 +02:00
committed by GitHub
parent 4d6cd3cb2a
commit 40b1b8f703
7 changed files with 102 additions and 16 deletions

View File

@@ -119,6 +119,29 @@ func ReaderToBytes(lines io.Reader) []byte {
return bc
}
// ToLowerMap makes all the keys in the given map lower cased and will do so
// recursively.
// Notes:
// * This will modify the map given.
// * Any nested map[interface{}]interface{} will be converted to map[string]interface{}.
func ToLowerMap(m map[string]interface{}) {
for k, v := range m {
switch v.(type) {
case map[interface{}]interface{}:
v = cast.ToStringMap(v)
ToLowerMap(v.(map[string]interface{}))
case map[string]interface{}:
ToLowerMap(v.(map[string]interface{}))
}
lKey := strings.ToLower(k)
if k != lKey {
delete(m, k)
}
m[lKey] = v
}
}
// ReaderToString is the same as ReaderToBytes, but returns a string.
func ReaderToString(lines io.Reader) string {
if lines == nil {