reflect.Type and reflect.Value
TypeOf, ValueOf, Kind, and Elem
reflect package overview
The reflect package allows Go programs to inspect types and values at runtime. It is the foundation of encoding libraries, ORMs, and dependency injection frameworks.
reflect.TypeOf
reflect.TypeOf(x) returns the reflect.Type of x's value:
t := reflect.TypeOf(42)
fmt.Println(t.Name()) // "int"
fmt.Println(t.Kind()) // "int"
fmt.Println(t.String()) // "int"All lessons in this course
- reflect.Type and reflect.Value
- Inspecting Struct Fields and Tags
- Dynamic Function Calls
- Practical Reflection: Serializers