aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Black <doug@dougblack.io>2014-04-24 20:52:41 -0700
committerDoug Black <doug@dougblack.io>2014-04-24 20:52:41 -0700
commit929e726c5f2604cdcb95a2e82b7002a51f1858aa (patch)
treecad5bc217f8d2a8692166bad49202e3a1f739e29
parents/muxPointer/mux/ (diff)
parentAlways create readable JSON strings. http://www.vinaysahni.com/best-practices... (diff)
downloadsleepy-929e726c5f2604cdcb95a2e82b7002a51f1858aa.tar.gz
sleepy-929e726c5f2604cdcb95a2e82b7002a51f1858aa.tar.bz2
sleepy-929e726c5f2604cdcb95a2e82b7002a51f1858aa.zip
Merge pull request #20 from strukturag/pretty_print
Always create readable JSON strings.
-rw-r--r--core.go2
-rw-r--r--core_test.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/core.go b/core.go
index 3aa0c7c..b15ca8b 100644
--- a/core.go
+++ b/core.go
@@ -91,7 +91,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
code, data, header := handler(request.Form, request.Header)
- content, err := json.Marshal(data)
+ content, err := json.MarshalIndent(data, "", " ")
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
return
diff --git a/core_test.go b/core_test.go
index 2438b98..8027bfe 100644
--- a/core_test.go
+++ b/core_test.go
@@ -27,7 +27,7 @@ func TestBasicGet(t *testing.T) {
t.Error(err)
}
body, _ := ioutil.ReadAll(resp.Body)
- if string(body) != `{"items":["item1","item2"]}` {
+ if string(body) != "{\n \"items\": [\n \"item1\",\n \"item2\"\n ]\n}" {
t.Error("Not equal.")
}
}
bgstack15