Get Variable Type
TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.
Here is a go lang example that shows how to get the type of a variable.
Source: (example.go)
package main
import (
"fmt"
"reflect"
)
func main() {
// integer
i := 1
// float
f := 1.23456
// string
s := "Hello World"
fmt.Println("i type: ", reflect.TypeOf(i))
fmt.Println("f type: ", reflect.TypeOf(f))
fmt.Println("s type: ", reflect.TypeOf(s))
}
Output:
$ go run example.go
i type: int
f type: float64
s type: string
Related Content:
https://golang.org/pkg/reflect
Questions answered by this page:
How to find a type of an object in Golang?
Go Lang example to get type of a variable
Print a Variables Type in golang