This is a created article in which the information may have evolved or changed.
Reflect. Value distinguishes between Canset and can not set, so it must be returned to the reflect of can set. Value
Such as:
S: = reflect. ValueOf (&t). Elem ()
Then you can set the value of the happy, but not arbitrarily set the value, a common method is to use the set (V Value) method, so the value must be converted to reflect. Value type, the following code is the one that goes to the value type
Slicevalue: = reflect. ValueOf ([]int{1, 2, 3})//turn slice into reflect here. Value type
Full reference:
Type T struct {age int Name string children []int}t: = t{12, "Someone-life", nil}s: = reflect. ValueOf (&t). Elem () S.field (0). Setint (123)//built-in common type set Value method Slicevalue: = Reflect. ValueOf ([]int{1, 2, 3})//turn slice into reflect here. The value type S.fieldbyname ("Children"). Set (Slicevalue)