1
0
mirror of https://github.com/labstack/echo.git synced 2025-03-21 21:27:04 +02:00

Gannett digital master allow html buffers ()

* 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 <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-12-06 18:57:06 -08:00 committed by GitHub
parent f10daac5d6
commit 1f0bae394a
2 changed files with 12 additions and 14 deletions
context.go
website/content/recipes

@ -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
@ -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) {

@ -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"