How to check data type in Golang?
March 26, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
Today’s Tutorial will focus on to check datatype in golang in the easiest way, here we try to check datatype in just two lines of code.
Follow the below tutorial if you are struggling in installing GO in windows.
https://aguidehub.com/blog/how-to-install-golang-in-windows/
Let’s start today’s tutorial How to check the data type of variable in Golang?
Here, we will use the go reflect
package to check data type and to show in the console we will use fmt.Print()
method.
let’s dive into code…
package main
import (
"fmt"
"reflect"
)
func main() {
data := 123
dataType := reflect.TypeOf(data).Kind()
fmt.Print(dataType)
}
in the above code, we are hole 123 in data variable and pass in reflect.TypeOf
and it returns their datatype.
it will show output int…
All the best 👍