Clone this repo:
  1. 9ff306d README: link to the newish `cmp` package by Kyle Lemons · 3 weeks ago master v1.1.0
  2. 7c2843e pretty: Note that Compare doesn't compare types. by Kyle Lemons · 3 weeks ago
  3. 8db7c34 Merge branch 'selfref' by Kyle Lemons · 3 weeks ago
  4. 009bb93 Create go.mod by Kyle Lemons · 4 weeks ago v1.0.0
  5. 7a67e28 Emit tags in ascending order during output by Kyle Lemons · 1 year, 6 months ago

Pretty Printing for Go

godebug build status

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!

Quick Examples

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

  • Pretty: godoc for godebug/pretty
  • Diff: godoc for godebug/diff


These packages are available via go get:

$ go get -u{pretty,diff}

Other Packages

If godebug/pretty is not granular enough, I highly recommend checking out cmp or go-spew.