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

Pretty-print and debug Go structs with a Laravel-inspired developer experience.

Go Reference License: MIT Go Test Go version Latest tag Go Report Card

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)

HTML Output Example

✨ Features

  • 🧠 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.)

📦 Installation

go get github.com/goforj/godump

🚀 Usage

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)
}

🧪 Example Output

<#dump // main.go:26
#main.User
  +Name    => "Alice"
  +Profile => #main.Profile
    +Age   => 30
    +Email => "[email protected]"
  }
}

📘 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

📇 Author

Created by Chris Miles
Maintained as part of the goforj tooling ecosystem.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published