After seeing how to handle the reflection basics, we will now see how complex data types such as structures and maps can also be handled using reflection.
Handling complex types
Data structures
For changeability, structures work in exactly the same way as the basic types; we need to obtain the reflection of the pointer, then access its element in order to be able to change the value, because using the structure directly would produce a copy of it and it would panic when changing values.
We can replace the value of the entire structure using the Set method, after obtaining the new value's reflection:
func main() {
type X struct {
A, B int
c string
}
var a = X{10, 100, "apple"}
...