Litter: a pretty printer library for Go

Litter is a pretty printer library for Go data structures to aid in debugging and testing.

Litter named for the fact that it outputs literals, which you litter your output with. As a side benefit, all Litter output is syntactically correct Go. You can use Litter to emit data during debug, and it’s also really nice for „snapshot data“ in unit tests, since it produces consistent, sorted output. Litter was inspired by Spew, but focuses on terseness and readability.

type Person struct {
	Name   string
	Age    int
	Parent *Person
}

litter.Dump(Person{
	Name:   "Bob",
	Age:    20,
	Parent: &Person{
		Name: "Jane",
		Age:  50,
	},
})

Output:

Person{
	Name: "Bob",
	Age: 20,
	Parent: &Person{
		Name: "Jane",
		Age: 50,
	},
}
Publikováno v Go