I have this piece of code, where I want to set the value of the pointer that is inside of a struct.
package main
import (
"fmt"
"reflect"
)
type MyStruct struct {
value *uint64 // value that I want to modify
}
func main() {
var i uint64 = 1
pointer := &MyStruct{&i}
elem := reflect.ValueOf(pointer).Elem()
field := elem.Field(0)
fmt.Println(field.CanSet(), field.Elem().CanSet())
}
Result:
false false
Unfortunately it is not settable. What can I do?
Aucun commentaire:
Enregistrer un commentaire