So I found some code that help me get started with reflection in Go (golang), but I\'m having trouble getting a the underlying value so that I can basically create a map[s
This should be easier to do with Go 1.5 (August 2015) See review 8731 and commit 049b89d by Rob Pike (robpike):
fmt: treatreflect.Valuespecially - as the value it holds
This would allow you to print the actual value of a Reflect.Value() argument:
When a
reflect.Valueis passed toPrintf(etc.),fmtcalled theStringmethod, which does not disclose its contents.
To get the contents, one could callValue.Interface(), but that is illegal if theValueis not exported or otherwise forbidden.This CL improves the situation with a trivial change to the
fmtpackage: when we see areflect.Valueas an argument, we treat it exactly as we treat areflect.Valuewe make inside the package.
This means that we always print the contents of theValueas if that was the argument toPrintf.This is arguably a breaking change but I think it is a genuine improvement and no greater a break than many other tweaks we have made to formatted output from this package.