A minimal, developer-friendly pretty-printer and debug dumper for Go structs, inspired by Laravel’s dump() and Symfony’s VarDumper.
A minimal, developer-friendly pretty-printer and debug dumper for Go structs, inspired by Laravel’s dump() and Symfony’s VarDumper.
<a href="https://codecov.io/gh/goforj/godump" ></a>
<a href="https://github.com/avelino/awesome-go?tab=readme-ov-file#parsersencodersdecoders"></a>
godump is a developer-friendly, zero-dependency debug dumper for Go. It provides pretty, colorized terminal output of your structs, slices, maps, and more - complete with cyclic reference detection and control character escaping.
Inspired by Symfony's VarDumper which is used in Laravel's tools like dump() and dd().
Terminal Output Example (Kitchen Sink)
HTML Output Example
godump.Diff(a,b) Output Example
godump vs go-spew vs pp| Feature | godump | go-spew | pp |
|---|---|---|---|
| Zero dependencies | ✓ | - | - |
| Colorized terminal output | ✓ | ✓ | ✓ |
| HTML output | ✓ | - | - |
JSON output helpers (DumpJSON, DumpJSONStr) |
✓ | - | - |
Diff output helpers (Diff, DiffStr) |
✓ | - | - |
Diff HTML output (DiffHTML) |
✓ | - | - |
Dump to io.Writer |
✓ | ✓ | ✓ |
| Shows file + line number of dump call | ✓ | - | - |
| Cyclic reference detection | ✓ | ~ | - |
| Handles unexported struct fields | ✓ | ✓ | ✓ |
Visibility markers (+ / -) |
✓ | - | - |
| Max depth control | ✓ | - | - |
| Max items (slice/map truncation) | ✓ | - | - |
| Max string length truncation | ✓ | - | - |
Dump & Die (dd() equivalent) |
✓ | - | - |
| Control character escaping | ✓ | ~ | ~ |
| Supports structs, maps, slices, pointers, interfaces | ✓ | ✓ | ✓ |
Pretty type name rendering (#package.Type) |
✓ | - | - |
| Builder-style configuration API | ✓ | - | - |
Test-friendly string output (DumpStr, DiffStr, DumpJSONStr) |
✓ | ✓ | ✓ |
| HTML / Web UI debugging support | ✓ | - | - |
If you'd like to suggest improvements or additional comparisons, feel free to open an issue or PR.
go get github.com/goforj/godumptype User struct { Name string }
godump.Dump(User{Name: "Alice"})
// #main.User {
// +Name => "Alice" #string
// } godump.DumpStr(v) // return as string
godump.DumpHTML(v) // return HTML output
godump.DumpJSON(v) // print JSON directly
godump.Fdump(w, v) // write to io.Writer
godump.Dd(v) // dump + exit
godump.Diff(a, b) // diff two values
godump.DiffStr(a, b) // diff two values as string
godump.DiffHTML(a, b) // diff two values as HTMLtype User struct {
Name string
}
before := User{Name: "Alice"}
after := User{Name: "Bob"}
godump.Diff(before, after)
// #main.User {
// - +Name => "Alice" #string
// + +Name => "Bob" #string
// }godump aims for simple usage with sensible defaults out of the box, but also provides a flexible builder-style API for customization.
If you want to heavily customize the dumper behavior, you can create a Dumper instance with specific options:
godump.NewDumper(
godump.WithMaxDepth(15), // default: 15
godump.WithMaxItems(100), // default: 100
godump.WithMaxStringLen(100000), // default: 100000
godump.WithWriter(os.Stdout), // default: os.Stdout
godump.WithSkipStackFrames(10), // default: 10
godump.WithDisableStringer(false), // default: false
godump.WithoutColor(), // default: false
).Dump(v)Ensure that all tests pass, and you run ./docs/generate.sh to update the API index in the README before submitting a PR.
Ensure all public functions have documentation blocks with examples, as these are used to generate runnable examples and the API index.
Every function has a corresponding runnable example under ./examples.
These examples are generated directly from the documentation blocks of each function, ensuring the docs and code never drift. These are the same examples you see here in the README and GoDoc.
An automated test executes every example to verify it builds and runs successfully.
This guarantees all examples are valid, up-to-date, and remain functional as the API evolves.
How to Read the Outputgodump output is designed for clarity and traceability. Here's how to interpret its structure:
<#dump // main.go:26godump.Dump() was invoked.#main.User +Name => "Alice"
-secret => "..."+ → Exported (public) field- → Unexported (private) field (accessed reflectively)If a pointer has already been printed:
↩︎ &1 0 => "value"
a => 1=> formatting and indentationmaxItems is exceeded"Line1\nLine2\tDone"\n, \t, \r, etc. are safely escapedmaxStringLen runes| Group | Functions |
|---|---|
| Builder | NewDumper |
| Diff | Diff · DiffHTML · DiffStr |
| Dump | Dd · Dump · DumpStr · Fdump |
| HTML | DumpHTML |
| JSON | DumpJSON · DumpJSONStr |
| Options | WithDisableStringer · WithExcludeFields · WithFieldMatchMode · WithMaxDepth · WithMaxItems · WithMaxStringLen · WithOnlyFields · WithRedactFields · WithRedactMatchMode · WithRedactSensitive · WithSkipStackFrames · WithWriter · WithoutColor · WithoutHeader |
NewDumper creates a new Dumper with the given options applied. Defaults are used for any setting not overridden.
v := map[string]int{"a": 1}
d := godump.NewDumper(
godump.WithMaxDepth(10),
godump.WithWriter(os.Stdout),
)
d.Dump(v)
// #map[string]int {
// a => 1 #int
// }Diff prints a diff between two values to stdout.
Example: print diff
a := map[string]int{"a": 1}
b := map[string]int{"a": 2}
godump.Diff(a, b)
// <#diff // path:line
// - #map[string]int {
// - a => 1 #int
// - }
// + #map[string]int {
// + a => 2 #int
// + }Example: print diff with a custom dumper
d := godump.NewDumper()
a := map[string]int{"a": 1}
b := map[string]int{"a": 2}
d.Diff(a, b)
// <#diff // path:line
// - #map[string]int {
// - a => 1 #int
// - }
// + #map[string]int {
// + a => 2 #int
// + }DiffHTML returns an HTML diff between two values.
Example: HTML diff
a := map[string]int{"a": 1}
b := map[string]int{"a": 2}
html := godump.DiffHTML(a, b)
_ = html
// (html diff)Example: HTML diff with a custom dumper
d := godump.NewDumper()
a := map[string]int{"a": 1}
b := map[string]int{"a": 2}
html := d.DiffHTML(a, b)
_ = html
// (html diff)DiffStr returns a string diff between two values.
Example: diff string
a := map[string]int{"a": 1}
b := map[string]int{"a": 2}
out := godump.DiffStr(a, b)
_ = out
// <#diff // path:line
// - #map[string]int {
// - a => 1 #int
// - }
// + #map[string]int {
// + a => 2 #int
// + }Example: diff string with a custom dumper
d := godump.NewDumper()
a := map[string]int{"a": 1}
b := map[string]int{"a": 2}
out := d.DiffStr(a, b)
_ = out
// <#diff // path:line
// - #map[string]int {
// - a => 1 #int
// - }
// + #map[string]int {
// + a => 2 #int
// + }Dd is a debug function that prints the values and exits the program.
Example: dump and exit
v := map[string]int{"a": 1}
godump.Dd(v)
// #map[string]int {
// a => 1 #int
// }Example: dump and exit with a custom dumper
d := godump.NewDumper()
v := map[string]int{"a": 1}
d.Dd(v)
// #map[string]int {
// a => 1 #int
// }Dump prints the values to stdout with colorized output.
Example: print to stdout
v := map[string]int{"a": 1}
godump.Dump(v)
// #map[string]int {
// a => 1 #int
// }Example: print with a custom dumper
d := godump.NewDumper()
v := map[string]int{"a": 1}
d.Dump(v)
// #map[string]int {
// a => 1 #int
// }DumpStr returns a string representation of the values with colorized output.
Example: get a string dump
v := map[string]int{"a": 1}
out := godump.DumpStr(v)
godump.Dump(out)
// "#map[string]int {\n a => 1 #int\n}" #stringExample: get a string dump with a custom dumper
d := godump.NewDumper()
v := map[string]int{"a": 1}
out := d.DumpStr(v)
_ = out
// "#map[string]int {\n a => 1 #int\n}" #stringFdump writes the formatted dump of values to the
No open issues yet, or sync has not completed.