Although it is possible to test whether an interface{}
is a map of known key/value type:
func TypeTest(thing interface{}) {
switch thing.(type) {
case map[string]string:
fmt.Println("map string string")
case map[string]interface{}:
fmt.Println("map string")
case map[interface{}]interface{}:
fmt.Println("map")
case interface{}:
fmt.Println("interface")
default:
fmt.Println("unknown")
}
}
TypeTest(map[string]string{"a": "1"}) // "map string string"
TypeTest(map[string]int{"a": 1}) // "interface" !!!
But what if I just want to know whether an interface{}
is a map or not, without worrying about its key/value type?