From 609587e6eb892d385d900923793e9d2c92f66036 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Mon, 11 Apr 2016 16:49:20 -0700 Subject: [PATCH] Fixed #463 Signed-off-by: Vishal Rana --- README.md | 6 ++++++ context.go | 7 +++++++ context_test.go | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 1d4b8739..55e3bb80 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,12 @@ Middleware | Description ##### [More...](https://labstack.com/echo/guide/middleware/) +#### Third-party Middleware + +Middleware | Description +:--- | :--- +[echoperm](https://github.com/xyproto/echoperm) | Keeping track of users, login states and permissions. + ### Next - Head over to [guide](https://labstack.com/echo/guide/installation/) diff --git a/context.go b/context.go index b5c8f789..55874824 100644 --- a/context.go +++ b/context.go @@ -124,6 +124,9 @@ type ( // Error invokes the registered HTTP error handler. Generally used by middleware. Error(err error) + // Handler returns the matched handler by router. + Handler() HandlerFunc + // Logger returns the `Logger` instance. Logger() *log.Logger @@ -408,6 +411,10 @@ func (c *context) Echo() *Echo { return c.echo } +func (c *context) Handler() HandlerFunc { + return c.handler +} + func (c *context) Logger() *log.Logger { return c.echo.logger } diff --git a/context_test.go b/context_test.go index 32a30f8d..a1547510 100644 --- a/context_test.go +++ b/context_test.go @@ -1,6 +1,7 @@ package echo import ( + "bytes" "errors" "io" "net/http" @@ -266,6 +267,21 @@ func TestContextServeContent(t *testing.T) { } } +func TestContextHandler(t *testing.T) { + e := New() + r := e.Router() + b := new(bytes.Buffer) + + r.Add(GET, "/handler", func(Context) error { + _, err := b.Write([]byte("handler")) + return err + }, e) + c := NewContext(nil, nil, e) + r.Find(GET, "/handler", c) + c.Handler()(c) + assert.Equal(t, "handler", b.String()) +} + func testBindOk(t *testing.T, c Context, ct string) { c.Request().Header().Set(HeaderContentType, ct) u := new(user)