Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Created November 7, 2023 16:34
Show Gist options
  • Save mortymacs/617b9feaba305960c3b126c6f54873a1 to your computer and use it in GitHub Desktop.
Save mortymacs/617b9feaba305960c3b126c6f54873a1 to your computer and use it in GitHub Desktop.
Find what data type is behind the any in Go
package main
import "fmt"
func GetData() any {
a := map[string]any{
"name": map[string]any{
"age": 1,
},
}
return a
}
func main() {
a := GetData()
b := a.(map[string]any)
switch b["name"].(type) {
case int:
fmt.Println("int")
case string:
fmt.Println("str")
case map[string]any:
fmt.Println("map!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment