Say I have the following code:
var x interface{}
y := 4
x = y
fmt.Println(reflect.TypeOf(x))
This will print int as the type. My question is how can I test for the type? I know there is the type switch which does this, so I could do:
switch x.(type) {
case int:
fmt.Println("This is an int")
}
But if I only want to check for just one specific type the switch seems like the wrong tool. Is there a more direct method of doing this like
reflect.TypeOf(x) == int
or is the type switch the way to go?