Xdumpgo - Tutorial
package main
import (
"github.com/wjeevm/xdumpgo"
)
type Server struct
Name string
IP string
Tags []string
func main()
servers := []Server
Name: "Prod-DB",
IP: "192.168.1.1",
Tags: []string"primary", "sql", "critical",
,
Name: "Cache-Redis",
IP: "192.168.1.2",
Tags: []string"cache", "redis",
,
// Dump the slice of structs
xdumpgo.Print(servers)
This will output a clearly formatted hierarchy, making it easy to distinguish between slice indices and struct fields.
package mainimport ( "os" "github.com/example/xdumpgo" )
func main() data := []byte("Hello xdumpgo! Let's inspect this sentence.") cfg := xdumpgo.DefaultConfig() cfg.GroupSize = 2 cfg.Endian = xdumpgo.LittleEndian cfg.Color = true
dump := xdumpgo.NewDumper(cfg) dump.Write(os.Stdout, data)
saveData, _ := os.ReadFile("game.sav")
cfg := xdumpgo.DefaultConfig()
cfg.GroupSize = 4
cfg.Endian = xdumpgo.LittleEndian
xdumpgo.NewDumper(cfg).Write(os.Stdout, saveData)
Spot checksum fields and embedded strings instantly.
xdumpgo is a Go library (and command-line tool) that allows developers to dump complex data structures into various formats (often XML or extended data formats). Unlike standard JSON marshaling which fails on circular references or unexported fields, xdumpgo uses reflection to provide a granular view of your data in memory. xdumpgo tutorial
Key Features:
Create schema.go:
type Event struct
TS uint64
Len uint16
Payload []byte
Then:
xdumpgo -type "Event" -repeated events.log
Output:
EventTS=1700000000, Len=5, Payload=[104 101 108 108 111]
You’re probably using non-streaming mode on a huge file. Switch to StreamDumper.
xdumpgo goroutines core.dump
Output:
Goroutine 1: running at main.main+0x12f
Goroutine 6: waiting on chan receive (runtime.chanrecv)
Create a file named main.go:
package main
import (
"fmt"
"github.com/wjeevm/xdumpgo" // Adjust import path based on your actual source
)
func main()
// Define a simple struct
user := struct
Name string
Age int
Role string
Name: "Alice",
Age: 30,
Role: "Admin",
// Standard fmt output
fmt.Println("--- Standard fmt output ---")
fmt.Printf("%+v\n", user)
// xdumpgo output
fmt.Println("\n--- xdumpgo output ---")
xdumpgo.Print(user)
Output Comparison:
The standard fmt package prints a flat line: Name:Alice Age:30 Role:Admin.
xdumpgo will output a colored, structured view (colors represented here conceptually):
(struct Name string; Age int; Role string )
Name: (string) "Alice",
Age: (int) 30,
Role: (string) "Admin",