Open flw-cn opened 4 years ago
I'd like to +1 this but for a different use case; child struct types of a parent struct sometimes associate with the parent via an unexported field. Sometimes these parents are huge.
For example,
type AVeryLargeThing struct {
// ...
RelatedThings []*SmallThing
// ...
}
type SmallThing struct {
Foo string
Bar *int
parentThing *AVeryLargeThing
}
If I want to dump a SmallThing
, I end up getting parentThing
in the process. In the case of e.g. things containing tls.Configs, etc. in unexported fields this can get quite large, and one is left either marshaling SmallThing to a more text-friendly representation (e.g. JSON) or explicitly print/dump/logging each exported field explicitly just to avoid the unexported field.
Sometimes I want the data structure I get from Dump () as I actually see it. This can be very useful for debugging APIs. I don't want to see data that I can't access at all.
I'm not sure if anyone mentioned something similar before. I tried searching but didn't find it.
Anyway, I implemented this on my fork and it seems to work fine. So I sent you a PR, I hope you can consider whether to merge or re-implement it by other means.
Thank you in advance.