I would like to create a reflect.Value
that represents a multiple-level nested pointer to a final value. The nesting level is not known at compile time. How can I create pointers to pointers using reflect
?
I already stumble at the "unaddressable value" hurdle when trying to create a pointer to a pointer.
dave := "It's full of stars!"
stargazer := reflect.ValueOf(&dave)
stargazer = stargazer.Addr() // panic: reflect.Value.Addr of unaddressable value
Same for stargazer.UnsafeAddr()
, etc. While stargazer.Elem().UnsafeAddr()
etc. works, I can't see how this helps in (recursively) creating a new non-zero pointer to a pointer...