Skip to content

Go: The Simplest Way to Dump complex Variables for Debugging

fmt package is magic! I love it and you can use it to simplify many tasks especially the debugging process 🙂

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

Take a look at this example and see how it is simple and you do not need any extra package to dump and debug variables:

package main

import "fmt"

type User struct {
	ID      int
	Address Address

type Address struct {
	Country string

func main() {

	simpleSlice := []string{

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

	user := User{
		ID: 123,
		Address: Address{
			Country: "FreeLand",

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

	// output:
	// []string{"hi"}
	// main.User{ID:123, Address:main.Address{Country:"FreeLand"}}

Leave a Reply

Your email address will not be published. Required fields are marked *