Merge pull request #47 from nwidger/master

Use jsoncolor package to colorize JSON bodies
pull/55/head
Adam Tauber 7 years ago committed by GitHub
commit 909107cb7e

@ -4,7 +4,6 @@ import (
"bytes"
"compress/gzip"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
@ -24,6 +23,7 @@ import (
"crypto/tls"
"github.com/jroimartin/gocui"
"github.com/mattn/go-runewidth"
"github.com/nwidger/jsoncolor"
)
const VERSION = "0.1.0"
@ -431,10 +431,11 @@ func (a *App) SubmitRequest(g *gocui.Gui, _ *gocui.View) error {
// pretty-print json
if strings.Contains(response.Header.Get("Content-Type"), "application/json") &&
a.config.General.FormatJSON {
var prettyJSON bytes.Buffer
err := json.Indent(&prettyJSON, r.RawResponseBody, "", " ")
formatter := jsoncolor.NewFormatter()
buf := bytes.NewBuffer(make([]byte, 0, len(r.RawResponseBody)))
err := formatter.Format(buf, r.RawResponseBody)
if err == nil {
r.RawResponseBody = prettyJSON.Bytes()
r.RawResponseBody = buf.Bytes()
}
}

Loading…
Cancel
Save