Lesson 28 of 60
GoReflection with the `reflect` Package
20 minutes
Course progress47%
Reflection Basics
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
reflect lets you inspect types at runtime – useful for generic libraries.
func Dump(v interface{}) {
rv := reflect.ValueOf(v)
rt := rv.Type()
fmt.Printf(, rt, rt.Kind())
i := ; i < rv.NumField(); i++ {
f := rt.Field(i)
val := rv.Field(i).Interface()
fmt.Printf(, f.Name, val)
}
}