github.com/wangyougui/gf/v2@v2.6.5/internal/utils/utils_map.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package utils 8 9 // MapPossibleItemByKey tries to find the possible key-value pair for given key ignoring cases and symbols. 10 // 11 // Note that this function might be of low performance. 12 func MapPossibleItemByKey(data map[string]interface{}, key string) (foundKey string, foundValue interface{}) { 13 if len(data) == 0 { 14 return 15 } 16 if v, ok := data[key]; ok { 17 return key, v 18 } 19 // Loop checking. 20 for k, v := range data { 21 if EqualFoldWithoutChars(k, key) { 22 return k, v 23 } 24 } 25 return "", nil 26 } 27 28 // MapContainsPossibleKey checks if the given `key` is contained in given map `data`. 29 // It checks the key ignoring cases and symbols. 30 // 31 // Note that this function might be of low performance. 32 func MapContainsPossibleKey(data map[string]interface{}, key string) bool { 33 if k, _ := MapPossibleItemByKey(data, key); k != "" { 34 return true 35 } 36 return false 37 }