package
0.0.0-20241218053035-7817f0a70428
Repository: https://github.com/lets-learn-it/go-learning.git
Documentation: pkg.go.dev
# README
Reflection
- It allows to examine and manipulate variables and types while your program is running.
- reflection may affect performance
- reflect package has 2 main types,
reflect.Type
andreflect.Value
reflect.Type
represents type of value whilereflect.Value
represents an instance of value.reflect.TypeOf()
andreflect.ValueOf()
function can be used to get them
Common Usages
- Custom struct tag
- dynamic type checking and type assertions
- iterating over struct fields
- implementing dependency injection: using
ValueOf
andSet
methods to set fields of structs at runtime.