1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-01 22:09:21 +02:00

Context.Redirect now returns an error

Context.Redirect will now return nil allowing users to do:
    return context.Redirect(...)
  rather that having to return nil everytime Redirect is used, ie:
    context.Redirect(...)
    return nil
This commit is contained in:
Chris Seto 2015-07-14 21:35:28 -04:00
parent 6d733d3120
commit 22ad37bace
2 changed files with 3 additions and 2 deletions

View File

@ -170,8 +170,9 @@ func (c *Context) NoContent(code int) error {
}
// Redirect redirects the request using http.Redirect with status code.
func (c *Context) Redirect(code int, url string) {
func (c *Context) Redirect(code int, url string) error {
http.Redirect(c.response, c.request, url, code)
return nil
}
// Error invokes the registered HTTP error handler. Generally used by middleware.

View File

@ -139,7 +139,7 @@ func TestContext(t *testing.T) {
// Redirect
rec = httptest.NewRecorder()
c = NewContext(req, NewResponse(rec), New())
c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo")
assert.Equal(t, nil, c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo"))
// Error
rec = httptest.NewRecorder()