From 22ad37bace4aeb483c17772d20e718ca61415f9f Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Tue, 14 Jul 2015 21:35:28 -0400 Subject: [PATCH] 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 --- context.go | 3 ++- context_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index a50732b6..f081f6d8 100644 --- a/context.go +++ b/context.go @@ -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. diff --git a/context_test.go b/context_test.go index 1fc703fa..39183e63 100644 --- a/context_test.go +++ b/context_test.go @@ -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()