Nicolas Martyanoff on Nostr: In #Go you cannot access the actual value behind a reflect.Value for non-exported ...
In #Go you cannot access the actual value behind a reflect.Value for non-exported values. But you can work around it using the unsafe package: grab the address of the value and recreate a new reflect.Value without the restriction:
reflect.NewAt(v.Type(), unsafe.Pointer(v.UnsafeAddr())).Elem()
Obviously not something to do for normal programs, but my pretty printer is for debugging so we're good.
This makes all the difference for go.n16f.net/pp, look at the modTime field before and after:
reflect.NewAt(v.Type(), unsafe.Pointer(v.UnsafeAddr())).Elem()
Obviously not something to do for normal programs, but my pretty printer is for debugging so we're good.
This makes all the difference for go.n16f.net/pp, look at the modTime field before and after: