To check the type of a value in Go is to use the %T verb in conjunction with fmt.Printf. This works well if you want to print the type to the console for debugging purposes.
Example:
package main
import "fmt"
func main() {
var a = "initial"
fmt.Printf("Type of a is %T\n", a)
var b int = 1
fmt.Printf("Type of b is %T\n", b)
var c float64 = 3.14
fmt.Printf("Type of c is %T\n", c)
var d = true
fmt.Printf("Type of d is %T\n", d)
}
Output:
Type of a is string
Type of b is int
Type of c is float64
Type of d is bool