added feat gethandler name

This commit is contained in:
miloud 2024-02-23 00:45:30 +01:00
parent ecdbbbe948
commit 173e12dcf7
1 changed files with 16 additions and 0 deletions

16
gin.go
View File

@ -291,6 +291,22 @@ func (engine *Engine) SetFuncMap(funcMap template.FuncMap) {
engine.FuncMap = funcMap
}
// GetHandlerPath takes a name of a handler and returns a slice of matched paths associated with that handler.
func (engine *Engine) GetHandlerPath(handlerName string) []string {
handlers := engine.Routes()
var paths []string
for _, f := range handlers {
handler := strings.Split(f.Handler, ".")
if handler[len(handler)-1] == handlerName {
paths = append(paths, f.Path)
}
}
return paths
}
// NoRoute adds handlers for NoRoute. It returns a 404 code by default.
func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
engine.noRoute = handlers