From df37629d4d5b6ebf1aca9a8d5c44b2deef6673c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Musab=20G=C3=BCltekin?= Date: Sun, 14 Jul 2019 03:37:52 +0300 Subject: [PATCH] Disabled indenting on JSON exporter as it looks so ugly on exported data. JSONLine still supports indenting. --- export/json.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/export/json.go b/export/json.go index cbaf938..d0affdd 100644 --- a/export/json.go +++ b/export/json.go @@ -8,7 +8,7 @@ import ( "os" ) -// JSON exports response data as JSON streaming file +// JSONLine exports response data as JSON streaming file type JSONLine struct { FileName string EscapeHTML bool @@ -43,8 +43,6 @@ func (e *JSONLine) Export(exports chan interface{}) { type JSON struct { FileName string EscapeHTML bool - Prefix string - Indent string } // Export exports response data as JSON @@ -62,7 +60,7 @@ func (e *JSON) Export(exports chan interface{}) { // Export data as responses came for res := range exports { - data, err := jsonMarshalLine(res, e.EscapeHTML, e.Prefix, e.Indent) + data, err := jsonMarshalLine(res, e.EscapeHTML) if err != nil { log.Printf("JSON encoding error on exporter: %v\n", err) continue @@ -79,12 +77,11 @@ func (e *JSON) Export(exports chan interface{}) { file.WriteAt([]byte("\n]\n"), stat.Size()-2) } -// jsonMarshalLine behaves like json.Marshal but supports escapeHTML and indenting -func jsonMarshalLine(t interface{}, escapeHTML bool, prefix string, indent string) ([]byte, error) { +// jsonMarshalLine adds tab and comma around actual data +func jsonMarshalLine(t interface{}, escapeHTML bool) ([]byte, error) { buffer := &bytes.Buffer{} encoder := json.NewEncoder(buffer) encoder.SetEscapeHTML(escapeHTML) - encoder.SetIndent(prefix, indent) buffer.Write([]byte(" ")) // Tab char err := encoder.Encode(t) // Write actual data