mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
cmd/syncthing: Return formatted JSON in API (#4945)
Because machines don't care, and sometimes humans read the output.
This commit is contained in:
parent
9e696a154b
commit
0c81fa4191
@ -219,14 +219,14 @@ func sendJSON(w http.ResponseWriter, jsonObject interface{}) {
|
|||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
// Marshalling might fail, in which case we should return a 500 with the
|
// Marshalling might fail, in which case we should return a 500 with the
|
||||||
// actual error.
|
// actual error.
|
||||||
bs, err := json.Marshal(jsonObject)
|
bs, err := json.MarshalIndent(jsonObject, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This Marshal() can't fail though.
|
// This Marshal() can't fail though.
|
||||||
bs, _ = json.Marshal(map[string]string{"error": err.Error()})
|
bs, _ = json.Marshal(map[string]string{"error": err.Error()})
|
||||||
http.Error(w, string(bs), http.StatusInternalServerError)
|
http.Error(w, string(bs), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(bs)
|
fmt.Fprintf(w, "%s\n", bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *apiService) Serve() {
|
func (s *apiService) Serve() {
|
||||||
|
Loading…
Reference in New Issue
Block a user