Pretty-print and debug Go structs with a Laravel-inspired developer experience.
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 (Simple)
Terminal Output Example (Kitchen Sink)
- 🧠 Struct field inspection with visibility markers (
+
,-
) - 🔄 Cycle-safe reference tracking
- 🎨 ANSI color or HTML output
- 🧪 Handles slices, maps, nested structs, pointers, time, etc.
- 🪄 Control character escaping (
\n
,\t
, etc.)
go get github.com/goforj/godump
package main
import (
"fmt"
"os"
"github.com/goforj/godump"
)
type Profile struct {
Age int
Email string
}
type User struct {
Name string
Profile Profile
}
func main() {
user := User{
Name: "Alice",
Profile: Profile{
Age: 30,
Email: "[email protected]",
},
}
// Pretty-print to stdout
godump.Dump(user)
// Dump and exit
godump.Dd(user) // this will print the dump and exit the program
// Get dump as string
output := godump.DumpStr(user)
fmt.Println("str", output)
// HTML for web UI output
html := godump.DumpHTML(user)
fmt.Println("html", html)
// Write to any io.Writer (e.g. file, buffer, logger)
godump.Fdump(os.Stderr, user)
}
<#dump // main.go:26
#main.User
+Name => "Alice"
+Profile => #main.Profile
+Age => 30
+Email => "[email protected]"
}
}
godump
output is designed for clarity and traceability. Here's how to interpret its structure:
<#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.
#main.User
- Fully qualified struct name with its package path.
+Name => "Alice"
-secret => "..."
+
→ Exported (public) field-
→ Unexported (private) field (accessed reflectively)
If a pointer has already been printed:
↩︎ &1
- Prevents infinite loops in circular structures
- References point back to earlier object instances
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
"Line1\nLine2\tDone"
- Control characters like
\n
,\t
,\r
, etc. are safely escaped - Strings are truncated after
maxStringLen
runes
- ✅ Structs (exported & unexported)
- ✅ Pointers, interfaces
- ✅ Maps, slices, arrays
- ✅ Channels, functions
- ✅ time.Time (nicely formatted)
MIT © goforj
Created by Chris Miles
Maintained as part of the goforj tooling ecosystem.