How to check data type in Golang?

Hi 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.

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 (

func main() {
	data := 123
	dataType := reflect.TypeOf(data).Kind()

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

Try it yourself

All the best 👍

Follow me on Twitter