Go lang
Programs
read csv file
find variable type in golang
for loops in golang
MongoDB sort() Method
MongoDB Find
MongoDB FindOne
differences between arrays and slices
InsertOne MongoDB
Connecting to MongoDB
how to use range in golang
Modules
Create a Go module
Create app using Go Module
Install
Installing GO lang

find variable type in golang



There are couple of ways to Find the Type of Variable in golang

Comparison: import and use reflect for comparing the variable

reflect.TypeOf Function

printing the Variable Type

Using %T with Printf

demo code

v1 := "string"
v2 := 2
v3 := 4.5
v4 := true
v5 := []string{"age", "name"}
v6 := map[string]float64{"apple": 3.2, "mango": 1.2}

fmt.Printf("v1: %T %s\n", v1, reflect.TypeOf(v1))
fmt.Printf("v2: %T %s\n", v2, reflect.TypeOf(v2))
fmt.Printf("v3: %T %s\n", v3, reflect.TypeOf(v3))
fmt.Printf("v4: %T %s\n", v4, reflect.TypeOf(v4))
fmt.Printf("v5: %T %s\n", v5, reflect.TypeOf(v5))
fmt.Printf("v6: %T %s\n", v6, reflect.TypeOf(v6))


output:

v1: string string
v2: int int
v3: float64 float64
v4: bool bool
v5: []string []string
v6: map[string]float64 map[string]float64



how to use range in golang

how to use range in golang

posted on 2022-05-03 08:28:11 - Go lang Tutorials


find variable type in golang

find variable type in golang

posted on 2022-05-03 05:24:55 - Go lang Tutorials


for loops in golang

for loops in golang

posted on 2022-05-03 04:27:40 - Go lang Tutorials


Run MongoDB On WSL Ubuntu

Run MongoDB On WSL Ubuntu

posted on 2022-04-28 05:02:09 - mongodb Tutorials


Installing MongoDB

Installing MongoDB

posted on 2022-04-28 04:16:57 - mongodb Tutorials


MySQL TRIGGERS

MySQL - Triggers

posted on 2019-11-29 21:44:07 - mysql Tutorials