switch to context.JSON

This commit is contained in:
Nazar Kanaev
2021-03-16 23:33:08 +00:00
parent 1e65da9aa4
commit 76937bedc9
3 changed files with 14 additions and 35 deletions

View File

@@ -22,14 +22,12 @@ func (c *Context) Next() {
}
func (c *Context) JSON(status int, data interface{}) {
reply, err := json.Marshal(data)
body, err := json.Marshal(data)
if err != nil {
log.Fatal(err)
c.Out.WriteHeader(http.StatusInternalServerError)
return
}
c.Out.WriteHeader(status)
c.Out.Header().Set("Content-Type", "application/json; charset=utf-8")
c.Out.Write(reply)
c.Out.Write(body)
c.Out.Write([]byte("\n"))
}