commit | 397d9a06b6442f58c63fa75896608473fe21bbb1 | [log] [tgz] |
---|---|---|
author | Kyle Lemons <kevlar@google.com> | Tue Nov 08 21:10:06 2016 |
committer | Kyle Lemons <kevlar@google.com> | Tue Nov 08 21:18:09 2016 |
tree | 9d9d36f97a92dad7fe11d4fed0a197b983a189a3 | |
parent | eadb3ce320cbab8393bea5ca17bebac3f78a021b [diff] |
Add a Formatter option to pretty.Config. The Formatter field is a map from reflect.Type to arbitrary function values that are callable with values of the given type and which return a string. The values will be printed literally. Fixes issues: #8, #11
Have you ever wanted to get a pretty-printed version of a Go data structure, complete with indentation? I have found this especially useful in unit tests and in debugging my code, and thus godebug was born!
By default, pretty will write out a very compact representation of a data structure. From the Print example:
{Name: "Spaceship Heart of Gold", Crew: {Arthur Dent: "Along for the Ride", Ford Prefect: "A Hoopy Frood", Trillian: "Human", Zaphod Beeblebrox: "Galactic President"}, Androids: 1, Stolen: true}
It can also produce a much more verbose, one-item-per-line representation suitable for computing diffs. See the documentation for more examples and customization.
Documentation for this package is available at godoc.org:
These packages are available via go get
:
$ go get -u github.com/kylelemons/godebug/{pretty,diff}
If godebug/pretty
is not granular enough, I highly recommend checking out go-spew.