Add method to return main handler

Fix #928 Method to get main handler is desired
This commit is contained in:
zhenghuabin 2017-06-02 14:08:46 +08:00
parent d5b353c5d5
commit 28c82b274e
2 changed files with 12 additions and 0 deletions

View File

@ -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 ***********/
/************************************/

View File

@ -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)