Pretty print json

This commit is contained in:
Mike Farah
2020-02-03 16:31:03 +11:00
parent b3598aaa43
commit 166f866f28
5 changed files with 49 additions and 30 deletions
+4 -1
View File
@@ -29,8 +29,11 @@ type jsonEncoder struct {
encoder *json.Encoder
}
func NewJsonEncoder(destination io.Writer) Encoder {
func NewJsonEncoder(destination io.Writer, prettyPrint bool) Encoder {
var encoder = json.NewEncoder(destination)
if prettyPrint {
encoder.SetIndent("", " ")
}
return &jsonEncoder{encoder}
}