package main import ( "fmt" "reflect" ) type Person struct { Name string Age int } func main() { p := Person{Name: "John", Age: 30} t := reflect.TypeOf(p) fmt.Println(t) // prints "main.Person" }
package main import ( "fmt" "reflect" ) func main() { x := 1 y := "hello" z := true printType(x) printType(y) printType(z) } func printType(val interface{}) { t := reflect.TypeOf(val) fmt.Println(t) }In this example, we define a `printType` function that takes an `interface{}` parameter and uses the `reflect.TypeOf` function to print the `Type` value of the parameter. We call this function with a few different values of different types, and we can see that it prints out the correct `Type` values for each one. The `Type` method is part of the standard library `reflect` package in Go.