Created
January 27, 2019 19:21
-
-
Save xsaamiir/1578f6b3049fe57fe837c64e17f34ed6 to your computer and use it in GitHub Desktop.
A function to visit every node in a map[string]interface{}
This file contains hidden or 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
func MapVisitor(mapToVisit map[string]interface{}) { | |
for k, v := range mapToVisit { | |
switch val := v.(type) { | |
case string: | |
fmt.Println(k, "is string -> ", val) | |
case float64: | |
fmt.Println(k, "is float64 -> ", val) | |
case map[string]interface{}: | |
MapVisitor(v.(map[string]interface{})) | |
case []interface{}: | |
for _, value := range val { | |
MapVisitor(value.(map[string]interface{})) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment