From 194ec11167ed0e7a97c560c1bd0acc98286e392c Mon Sep 17 00:00:00 2001 From: Fabian Holler Date: Tue, 19 Jun 2018 15:41:20 +0200 Subject: [PATCH] add a prettyprint package add a prettyprint package with an AsString() functionat that converts things to indented JSON --- prettyprint/prettyprint.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 prettyprint/prettyprint.go diff --git a/prettyprint/prettyprint.go b/prettyprint/prettyprint.go new file mode 100644 index 000000000..3cdd27ee5 --- /dev/null +++ b/prettyprint/prettyprint.go @@ -0,0 +1,16 @@ +package prettyprint + +import ( + "encoding/json" + "fmt" +) + +// AsString returns in as indented JSON +func AsString(in interface{}) string { + res, err := json.MarshalIndent(in, "", " ") + if err != nil { + return fmt.Sprintf("%+v", in) + } + + return string(res) +}