Skip to content

Instantly share code, notes, and snippets.

@techtonik
Created September 3, 2016 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techtonik/515374aa6cce2828fd9253486945f098 to your computer and use it in GitHub Desktop.
Save techtonik/515374aa6cce2828fd9253486945f098 to your computer and use it in GitHub Desktop.
Go - PP() - pretty printer for variables
package pp
import (
"fmt"
"encoding/json"
)
// Pretty print structures. Uses "encoding/json" to
// convert nested structure to indented string.
func PP(v interface{}) {
b, err := json.MarshalIndent(v, "", " ")
if err != nil {
fmt.Printf("error: %s", err)
}
fmt.Printf("%T %v\n", v, string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment