1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-17 01:43:02 +02:00

Removed prinftf from Context#String and Context#HTML, #154

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-11-24 20:03:15 -08:00
parent 754c84596e
commit f54cdd86d0
5 changed files with 19 additions and 30 deletions

View File

@ -6,8 +6,6 @@ import (
"net/http"
"path/filepath"
"fmt"
"net/url"
"bytes"
@ -60,7 +58,7 @@ func (c *Context) Socket() *websocket.Conn {
return c.socket
}
// Path returns the registered path for a handler.
// Path returns the registered path for the handler.
func (c *Context) Path() string {
return c.path
}
@ -134,31 +132,19 @@ func (c *Context) Render(code int, name string, data interface{}) (err error) {
return
}
// HTML formats according to a format specifier and sends HTML response with
// status code.
func (c *Context) HTML(code int, format string, a ...interface{}) (err error) {
buf := new(bytes.Buffer)
_, err = fmt.Fprintf(buf, format, a...)
if err != nil {
return err
}
// HTML sends an HTTP response with status code.
func (c *Context) HTML(code int, html string) (err error) {
c.response.Header().Set(ContentType, TextHTMLCharsetUTF8)
c.response.WriteHeader(code)
c.response.Write(buf.Bytes())
c.response.Write([]byte(html))
return
}
// String formats according to a format specifier and sends text response with status
// code.
func (c *Context) String(code int, format string, a ...interface{}) (err error) {
buf := new(bytes.Buffer)
_, err = fmt.Fprintf(buf, format, a...)
if err != nil {
return err
}
// String sends a string response with status code.
func (c *Context) String(code int, s string) (err error) {
c.response.Header().Set(ContentType, TextPlain)
c.response.WriteHeader(code)
c.response.Write(buf.Bytes())
c.response.Write([]byte(s))
return
}