What is Nostr?
Nicolas Martyanoff /
npub1dkg…54dt
2024-11-11 11:32:14

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:

Author Public Key
npub1dkg70vzk4vvfsc5cup9gkfu2tcrs5unysl7npfvegf78nkuswr5skh54dt