diff --git a/context.go b/context.go index df001a40..eccb93d5 100644 --- a/context.go +++ b/context.go @@ -83,6 +83,11 @@ func (c *Context) HandlerName() string { return nameOfFunction(c.handlers.Last()) } +// Handler returns the main handler. +func (c *Context) Handler() HandlerFunc { + return c.handlers.Last() +} + /************************************/ /*********** FLOW CONTROL ***********/ /************************************/ diff --git a/context_test.go b/context_test.go index 01ee6b83..e5547010 100644 --- a/context_test.go +++ b/context_test.go @@ -161,6 +161,13 @@ func handlerNameTest(c *Context) { } +func TestContextHandler(t *testing.T) { + c, _, _ := CreateTestContext() + c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest} + + assert.Equal(t, handlerNameTest, c.Handler()) +} + func TestContextQuery(t *testing.T) { c, _, _ := CreateTestContext() c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10&id=", nil)