Skip to content

Instantly share code, notes, and snippets.

@xsaamiir
Created January 27, 2019 19:21
Show Gist options
  • Save xsaamiir/1578f6b3049fe57fe837c64e17f34ed6 to your computer and use it in GitHub Desktop.
Save xsaamiir/1578f6b3049fe57fe837c64e17f34ed6 to your computer and use it in GitHub Desktop.
A function to visit every node in a map[string]interface{}
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