Skip to content

Commit

Permalink
add a prettyprint package
Browse files Browse the repository at this point in the history
add a prettyprint package with an AsString() functionat that converts
things to indented JSON
  • Loading branch information
fho committed Jun 19, 2018
1 parent a0ab8c0 commit 194ec11
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions prettyprint/prettyprint.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 194ec11

Please sign in to comment.