From eed30582ae25b16865edf756dba22663c7197164 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Mon, 6 Apr 2015 07:52:00 -0700 Subject: [PATCH] c.Text > c.String Signed-off-by: Vishal Rana --- README.md | 4 ++-- context.go | 10 +++++----- echo.go | 2 +- echo_test.go | 6 +++--- example/main.go | 4 ++-- response_test.go | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e9f0b749..c48413a1 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ func main() { sub.Use(func(c *echo.Context) { // Middleware }) sub.Get("/home", func(c *echo.Context) { - c.Text(http.StatusOK, "Sub route /sub/welcome") + c.String(http.StatusOK, "Sub route /sub/welcome") }) // Group - doesn't inherit parent middleware @@ -125,7 +125,7 @@ func main() { grp.Use(func(c *echo.Context) { // Middleware }) grp.Get("/home", func(c *echo.Context) { - c.Text(http.StatusOK, "Group route /group/welcome") + c.String(http.StatusOK, "Group route /group/welcome") }) // Start server diff --git a/context.go b/context.go index f2646db7..05271f6a 100644 --- a/context.go +++ b/context.go @@ -53,7 +53,7 @@ func (c *Context) Render(code int, i interface{}) error { if strings.HasPrefix(a, MIMEJSON) { return c.JSON(code, i) } else if strings.HasPrefix(a, MIMEText) { - return c.Text(code, i.(string)) + return c.String(code, i.(string)) } else if strings.HasPrefix(a, MIMEHTML) { } return c.HTML(code, i.(string)) @@ -66,15 +66,15 @@ func (c *Context) JSON(code int, i interface{}) error { return json.NewEncoder(c.Response).Encode(i) } -// Text sends a text/plain response with status code. -func (c *Context) Text(code int, s string) (err error) { +// String sends a text/plain response with status code. +func (c *Context) String(code int, s string) (err error) { c.Response.Header().Set(HeaderContentType, MIMEText+"; charset=utf-8") c.Response.WriteHeader(code) _, err = c.Response.Write([]byte(s)) return } -// HTML sends an html/plain response with status code. +// HTML sends a text/html response with status code. func (c *Context) HTML(code int, html string) (err error) { c.Response.Header().Set(HeaderContentType, MIMEHTML+"; charset=utf-8") c.Response.WriteHeader(code) @@ -83,7 +83,7 @@ func (c *Context) HTML(code int, html string) (err error) { } // HTMLTemplate applies the template associated with t that has the given name to -// the specified data object and sends an html/plain response with status code. +// the specified data object and sends a text/html response with status code. func (c *Context) HTMLTemplate(code int, t *template.Template, name string, data interface{}) (err error) { return t.ExecuteTemplate(c.Response, name, data) } diff --git a/echo.go b/echo.go index 4c295058..48cd8dc8 100644 --- a/echo.go +++ b/echo.go @@ -35,7 +35,7 @@ const ( MIMEJSON = "application/json" MIMEText = "text/plain" - MIMEHTML = "html/plain" + MIMEHTML = "text/html" MIMEForm = "application/x-www-form-urlencoded" MIMEMultipartForm = "multipart/form-data" diff --git a/echo_test.go b/echo_test.go index 017dc8c6..8ac30cae 100644 --- a/echo_test.go +++ b/echo_test.go @@ -92,7 +92,7 @@ func TestEchoMiddleware(t *testing.T) { // Route e.Get("/hello", func(c *Context) { - c.Text(200, "world") + c.String(200, "world") }) w := httptest.NewRecorder() @@ -111,7 +111,7 @@ func TestEchoHandler(t *testing.T) { // func(*echo.Context) e.Get("/1", func(c *Context) { - c.Text(http.StatusOK, "1") + c.String(http.StatusOK, "1") }) w := httptest.NewRecorder() r, _ := http.NewRequest(GET, "/1", nil) @@ -214,7 +214,7 @@ func TestEchoNotFound(t *testing.T) { // Customized NotFound handler e.NotFoundHandler(func(c *Context) { - c.Text(404, "not found") + c.String(404, "not found") }) w = httptest.NewRecorder() e.ServeHTTP(w, r) diff --git a/example/main.go b/example/main.go index 8540dd51..fc4f0a22 100644 --- a/example/main.go +++ b/example/main.go @@ -88,7 +88,7 @@ func main() { sub.Use(func(c *echo.Context) { // Middleware }) sub.Get("/home", func(c *echo.Context) { - c.Text(http.StatusOK, "Sub route /sub/welcome") + c.String(http.StatusOK, "Sub route /sub/welcome") }) // Group - doesn't inherit parent middleware @@ -96,7 +96,7 @@ func main() { grp.Use(func(c *echo.Context) { // Middleware }) grp.Get("/home", func(c *echo.Context) { - c.Text(http.StatusOK, "Group route /group/welcome") + c.String(http.StatusOK, "Group route /group/welcome") }) // Start server diff --git a/response_test.go b/response_test.go index fe49a28f..3bbae717 100644 --- a/response_test.go +++ b/response_test.go @@ -9,7 +9,7 @@ import ( func TestResponse(t *testing.T) { e := New() e.Get("/hello", func(c *Context) { - c.Text(http.StatusOK, "world") + c.String(http.StatusOK, "world") // Status if c.Response.Status() != http.StatusOK {