package main import ( "fmt" "reflect" ) func main() { var num int64 = 999 fmt.Println(reflect.TypeOf(num)) // prints "int64" }
package main import ( "fmt" "reflect" ) func main() { var num int64 = 999 fmt.Println(reflect.TypeOf(num) == reflect.TypeOf(int64(0))) // true }
package main import ( "fmt" "reflect" ) type Person struct { Name string Age int Address string } func main() { p := Person{Name: "John", Age: 30, Address: "123 Main St."} t := reflect.TypeOf(p) for i := 0; i < t.NumField(); i++ { fmt.Println(t.Field(i).Name) } // prints "Name", "Age", "Address" }- This code example shows how to use the Type field to obtain the fields of a struct. The reflect package is part of the Go standard library.