Changing Structure Values Using Reflection
Let’s learn how to change values using reflection in the Go structure.
We'll cover the following...
Learning about the internal structure of a Go structure is handy, but what is more practical is being able to change values in the Go structure, which is the subject of this lesson.
Coding example
Let’s look at the setValues.go
code:
Press + to interact
package mainimport ("fmt""reflect")type T struct {F1 intF2 stringF3 float64}
In the code above, we define a struct type named T
with three fields: F1
of type int
, F2
of type string
, and F3
...