summaryrefslogtreecommitdiffstats
path: root/helpers/general.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-10-16 19:28:21 +0200
committerGitHub <noreply@github.com>2016-10-16 19:28:21 +0200
commit40b1b8f70373dacf2458fbd9a67be32fc6830f91 (patch)
treefb03f4cde8daecd30c5e85c989a38a9fde5a2b3c /helpers/general.go
parent4d6cd3cb2aa46df781adde8debf9f64d50973365 (diff)
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
Diffstat (limited to 'helpers/general.go')
-rw-r--r--helpers/general.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/helpers/general.go b/helpers/general.go
index b420bfa2c..ba828ed8c 100644
--- a/helpers/general.go
+++ b/helpers/general.go
@@ -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 {