mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
c.Text > c.String
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
86138ed18e
commit
eed30582ae
@ -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
|
||||
|
10
context.go
10
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)
|
||||
}
|
||||
|
2
echo.go
2
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"
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user