Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,7 @@ func (c *context) JSON(code int, i interface{}) (err error) {
if c.echo.Debug || pretty {
return c.JSONPretty(code, i, " ")
}
b, err := json.Marshal(i)
if err != nil {
return
}
return c.JSONBlob(code, b)
return c.jsonBlob(code, i)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since jsonBlob is simple, the code can be moved directly here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah! nice job

}

func (c *context) JSONPretty(code int, i interface{}, indent string) (err error) {
Expand All @@ -428,6 +424,12 @@ func (c *context) JSONBlob(code int, b []byte) (err error) {
return c.Blob(code, MIMEApplicationJSONCharsetUTF8, b)
}

func (c *context) jsonBlob(code int, i interface{}) (err error) {
c.writeContentType(MIMEApplicationJSONCharsetUTF8)
c.response.WriteHeader(code)
return json.NewEncoder(c.response).Encode(i)
}

func (c *context) JSONP(code int, callback string, i interface{}) (err error) {
b, err := json.Marshal(i)
if err != nil {
Expand Down