mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 13:26:07 +00:00
Terminates pretty responses with a newline.
This commit is contained in:
parent
23545f97fe
commit
1fefdcb962
@ -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…
x
Reference in New Issue
Block a user