mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-11 00:56:57 +08:00
Add method to return main handler
Fix #928 Method to get main handler is desired
This commit is contained in:
parent
d5b353c5d5
commit
28c82b274e
@ -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 ***********/
|
||||
/************************************/
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user