mirror of
https://github.com/labstack/echo.git
synced 2024-12-22 20:06:21 +02:00
parent
fd5f48a884
commit
4e57fa0557
12
context.go
12
context.go
@ -159,10 +159,7 @@ func (c *Context) JSON(code int, i interface{}) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.response.Header().Set(ContentType, ApplicationJSONCharsetUTF8)
|
return c.JSONBlob(code, b)
|
||||||
c.response.WriteHeader(code)
|
|
||||||
c.response.Write(b)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONIndent sends a JSON response with status code, but it applies prefix and indent to format the output.
|
// JSONIndent sends a JSON response with status code, but it applies prefix and indent to format the output.
|
||||||
@ -171,14 +168,15 @@ func (c *Context) JSONIndent(code int, i interface{}, prefix string, indent stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.json(code, b)
|
return c.JSONBlob(code, b)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) json(code int, b []byte) {
|
// JSONBlob sends a JSON blob response with status code.
|
||||||
|
func (c *Context) JSONBlob(code int, b []byte) (err error) {
|
||||||
c.response.Header().Set(ContentType, ApplicationJSONCharsetUTF8)
|
c.response.Header().Set(ContentType, ApplicationJSONCharsetUTF8)
|
||||||
c.response.WriteHeader(code)
|
c.response.WriteHeader(code)
|
||||||
c.response.Write(b)
|
c.response.Write(b)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONP sends a JSONP response with status code. It uses `callback` to construct
|
// JSONP sends a JSONP response with status code. It uses `callback` to construct
|
||||||
|
Loading…
Reference in New Issue
Block a user