Terminates pretty responses with a newline.
This commit is contained in:
parent
907d8bab34
commit
54b930103c
|
@ -362,10 +362,17 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
|||
func (s *HTTPServer) marshalJSON(req *http.Request, obj interface{}) ([]byte, error) {
|
||||
if _, ok := req.URL.Query()["pretty"]; ok {
|
||||
buf, err := json.MarshalIndent(obj, "", " ")
|
||||
return buf, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buf = append(buf, "\n"...)
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
buf, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf, err
|
||||
}
|
||||
|
||||
|
|
|
@ -328,6 +328,7 @@ func testPrettyPrint(pretty string, t *testing.T) {
|
|||
srv.wrap(handler)(resp, req)
|
||||
|
||||
expected, _ := json.MarshalIndent(r, "", " ")
|
||||
expected = append(expected, "\n"...)
|
||||
actual, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
|
Loading…
Reference in New Issue