github.com/olliephillips/hugo@v0.42.2/common/maps/maps.go (about) 1 // Copyright 2018 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package maps 15 16 import ( 17 "strings" 18 19 "github.com/spf13/cast" 20 ) 21 22 // ToLower makes all the keys in the given map lower cased and will do so 23 // recursively. 24 // Notes: 25 // * This will modify the map given. 26 // * Any nested map[interface{}]interface{} will be converted to map[string]interface{}. 27 func ToLower(m map[string]interface{}) { 28 for k, v := range m { 29 switch v.(type) { 30 case map[interface{}]interface{}: 31 v = cast.ToStringMap(v) 32 ToLower(v.(map[string]interface{})) 33 case map[string]interface{}: 34 ToLower(v.(map[string]interface{})) 35 } 36 37 lKey := strings.ToLower(k) 38 if k != lKey { 39 delete(m, k) 40 m[lKey] = v 41 } 42 43 } 44 }