Add pretty output for json
egorsmkv opened this issue · comments
Yehor Smoliakov commented
Add pretty output for json
Ahmet Alp Balkan commented
Yehor Smoliakov commented
@ahmetalpbalkan Yes. I'll send a PR after some time.
Ahmet Alp Balkan commented
I just patched like this, additionally eliminating the error check (errors.Wrap handles that):
commit 8be476d20feeee97a216596fa63ed5a791d33812
Author: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
Date: Wed Nov 16 14:34:25 2016 -0800
Indent JSON responses, eliminate redundant err chk
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
diff --git a/util.go b/util.go
index cc414e3..fa75ac9 100644
--- a/util.go
+++ b/util.go
@@ -10,10 +10,9 @@ import (
)
func writeJSON(w io.Writer, v interface{}) error {
- if err := json.NewEncoder(w).Encode(v); err != nil {
- return errors.Wrap(err, "failed to encode JSON")
- }
- return nil
+ e := json.NewEncoder(w)
+ e.SetIndent("", " ")
+ return errors.Wrap(e.Encode(v), "failed to encode JSON")
}
func writeErrorJSON(w http.ResponseWriter, err error) {
Want me to just go ahead and submit?
Yehor Smoliakov commented
Yes, patch.
Yehor Smoliakov commented
Thanks, @ahmetalpbalkan!