github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/helpers/string_keyed_map.go (about) 1 package helpers 2 3 import ( 4 "fmt" 5 "reflect" 6 ) 7 8 func ToStringKeyedMap(m interface{}) (map[string]interface{}, error) { 9 newMap := make(map[string]interface{}) 10 rValue := reflect.ValueOf(m) 11 rKind := rValue.Kind() 12 switch rKind { 13 case reflect.Invalid: 14 return newMap, nil 15 case reflect.Map: 16 for _, rMapKey := range rValue.MapKeys() { 17 newMap[fmt.Sprintf("%s", rMapKey.Interface())] = rValue.MapIndex(rMapKey).Interface() 18 } 19 default: 20 return nil, fmt.Errorf("Value %s is not a map", rKind) 21 } 22 return newMap, nil 23 }