mirror of
https://github.com/nkanaev/yarr.git
synced 2025-12-15 16:40:04 +00:00
switch to context.JSON
This commit is contained in:
@@ -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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user