Add context.HandlerNames()

This change adds a HandlerNames method that will return all registered handles in the context, in descending order

This is useful for debugging and troubleshooting purposes, especially in large apps
This commit is contained in:
Luis GG 2019-01-02 13:40:11 -03:00 committed by GitHub
parent d8fb18c33b
commit 5eb80c422c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,6 +91,16 @@ func (c *Context) HandlerName() string {
return nameOfFunction(c.handlers.Last()) return nameOfFunction(c.handlers.Last())
} }
// HandlerNames returns a list of all registered handlers for this context in descending order,
// following the semantics of HandlerName()
func (c *Context) HandlerNames() []string {
hn := make([]string, 0, len(c.handlers))
for _, val := range c.handlers {
hn = append(hn, nameOfFunction(val))
}
return hn
}
// Handler returns the main handler. // Handler returns the main handler.
func (c *Context) Handler() HandlerFunc { func (c *Context) Handler() HandlerFunc {
return c.handlers.Last() return c.handlers.Last()