Skip to content

Printing out a struct in Go

Alright, this is very much “solely so it’s easy for me to find it”.

For lots of string formatting, Go by Example has a long set of examples. But the thing I’m probably thinking of is:

fmt.Printf("%#v\n", myVar)

Which “prints a Go syntax representation of the value, i.e. the source code snippet that would produce that value.”

Percent-Pound-v (and don’t forget a newline).

Handy for “I want to see all the things going in in this variable” when poking around and debugging.

2 Replies to “Printing out a struct in Go”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.