Skip to content

Commit

Permalink
Gannett digital master allow html buffers (labstack#765)
Browse files Browse the repository at this point in the history
* Since some templating engines final result is a buffer, we've been casting them to strings, which is a bit unnecessary considering under the hood Echo supports this.

* Since some templating engines final result is a buffer, we've been casting them to strings, which is a bit unnecessary considering under the hood Echo supports this.

* Update context.go

* Update context_test.go

* Update context_test.go

* Utilize same design pattern for HTMLBlob as JSONBlob

* Streamlined a few more methods

* more  consistent

Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr authored Dec 7, 2016
1 parent f10daac commit 1f0bae3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
22 changes: 10 additions & 12 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ type (
// HTML sends an HTTP response with status code.
HTML(int, string) error

// HTMLBlob sends an HTTP blob response with status code.
HTMLBlob(int, []byte) error

// String sends a string response with status code.
String(int, string) error

Expand Down Expand Up @@ -349,24 +352,19 @@ func (c *context) Render(code int, name string, data interface{}) (err error) {
if err = c.echo.Renderer.Render(buf, name, data, c); err != nil {
return
}
c.response.Header().Set(HeaderContentType, MIMETextHTMLCharsetUTF8)
c.response.WriteHeader(code)
_, err = c.response.Write(buf.Bytes())
return
return c.HTMLBlob(code, buf.Bytes())
}

func (c *context) HTML(code int, html string) (err error) {
c.response.Header().Set(HeaderContentType, MIMETextHTMLCharsetUTF8)
c.response.WriteHeader(code)
_, err = c.response.Write([]byte(html))
return
return c.HTMLBlob(code, []byte(html))
}

func (c *context) HTMLBlob(code int, b []byte) (err error) {
return c.Blob(code, MIMETextHTMLCharsetUTF8, b)
}

func (c *context) String(code int, s string) (err error) {
c.response.Header().Set(HeaderContentType, MIMETextPlainCharsetUTF8)
c.response.WriteHeader(code)
_, err = c.response.Write([]byte(s))
return
return c.Blob(code, MIMETextPlainCharsetUTF8, []byte(s))
}

func (c *context) JSON(code int, i interface{}) (err error) {
Expand Down
4 changes: 2 additions & 2 deletions website/content/recipes/twitter.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "Twitter API Example"
description = "Twitter API example for Echo"
title = "Twitter Like API Example"
description = "Twitter Like API example for Echo"
[menu.main]
name = "Twitter"
parent = "recipes"
Expand Down

0 comments on commit 1f0bae3

Please sign in to comment.