Created
September 3, 2016 06:32
-
-
Save techtonik/515374aa6cce2828fd9253486945f098 to your computer and use it in GitHub Desktop.
Go - PP() - pretty printer for variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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