Alternative way to check the type of a variable in Golang

An alternative way to determine the type of a value is to use the TypeOf method from the reflect package.

Example:

package main

import (
	 "fmt"
	 "reflect"
       )

func main() {

    var a = "initial"
    fmt.Println("Type of a is", reflect.TypeOf(a))

    var b int = 1
    fmt.Println("Type of b is", reflect.TypeOf(b))

    var c = 3.14
    fmt.Println("Type of c is", reflect.TypeOf(c))

    var d = true
    fmt.Println("Type of d is", reflect.TypeOf(d))
}
Output:
Type of a is string
Type of b is int
Type of c is float64
Type of d is bool