Created
May 30, 2013 07:52
-
-
Save cihangir/5676347 to your computer and use it in GitHub Desktop.
switch / reflect Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get type of current value | |
typeOfKey := reflect.TypeOf(v).String() | |
//every v, will be a string at the end | |
switch typeOfKey { | |
//if we have an complex type, resolve it | |
case "map[string]interface {}": | |
//convert value to its real type | |
tempVal := v.(map[string]interface{}) | |
//we have a lot more to-do, call recursively | |
src := ConvertTo2DMap(k, tempVal) | |
//get result and map while iterating | |
for mapKey, mapValue := range src { | |
//e.g.=> pages.0.items.1.id : 50e61fc71964f6a837000003 | |
tempKey := k + "." + mapKey | |
result[tempKey] = mapValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment