Skip to content
/ godump Public

A minimal, developer-friendly pretty-printer and debug dumper for Go structs, inspired by Laravel’s dump() and Symfony’s VarDumper.

License

Notifications You must be signed in to change notification settings

goforj/godump

Repository files navigation

godump logo – Go pretty printer and Laravel-style dump/dd debugging tool

Go Reference License: MIT Go Test Go version Latest tag Go Report Card Mentioned in Awesome Go

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)
Terminal output example kitchen sink

HTML Output Example
HTML output example

📊 Comparison: godump vs go-spew vs pp

Feature godump go-spew pp
Zero dependencies
Colorized terminal output
HTML output
JSON output helpers (DumpJSON, DumpJSONStr)
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, DumpHTML, DumpJSONStr)
HTML / Web UI debugging support

If you'd like to suggest improvements or additional comparisons, feel free to open an issue or PR.

📦 Installation

go get github.com/goforj/godump

🚀 Basic Usage

View Full Runnable Example →

type User struct { Name string }
godump.Dump(User{Name: "Alice"})
// #main.User {
//    +Name => "Alice" #string
// }	

🧰 Extended Usage (Snippets)

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

🏗️ Builder Options Usage

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:

View Full Runnable Example →

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
).Dump(v)

📁 Full Examples Directory

All runnable examples can be found under ./examples:

📘 How to Read the Output

godump output is designed for clarity and traceability. Here's how to interpret its structure:

🧭 Location Header

<#dump // main.go:26
  • The first line shows the file and line number where godump.Dump() was invoked.
  • Helpful for finding where the dump happened during debugging.

🔎 Type Names

#main.User
  • Fully qualified struct name with its package path.

🔐 Visibility Markers

  +Name => "Alice"
  -secret  => "..."
  • + → Exported (public) field
  • - → Unexported (private) field (accessed reflectively)

🔄 Cyclic References

If a pointer has already been printed:

↩︎ &1
  • Prevents infinite loops in circular structures
  • References point back to earlier object instances

🔢 Slices and Maps

  0 => "value"
  a => 1
  • Array/slice indices and map keys are shown with => formatting and indentation
  • Slices and maps are truncated if maxItems is exceeded

🔣 Escaped Characters

"Line1\nLine2\tDone"
  • Control characters like \n, \t, \r, etc. are safely escaped
  • Strings are truncated after maxStringLen runes

🧩 Supported Types

  • ✅ Structs (exported & unexported)
  • ✅ Pointers, interfaces
  • ✅ Maps, slices, arrays
  • ✅ Channels, functions
  • ✅ time.Time (nicely formatted)

🧩 License

MIT © goforj

About

A minimal, developer-friendly pretty-printer and debug dumper for Go structs, inspired by Laravel’s dump() and Symfony’s VarDumper.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 13