mirror of https://github.com/gofiber/fiber.git
Support Naming Routes
parent
4aafc504ad
commit
85d7a6add4
15
app.go
15
app.go
|
@ -386,7 +386,20 @@ func (app *App) Routes() []*Route {
|
|||
if m == 1 && app.stack[m][r].Method == MethodGet {
|
||||
continue
|
||||
}
|
||||
routes = append(routes, app.stack[m][r])
|
||||
// Don't duplicate USE routes
|
||||
if app.stack[m][r].Method == "USE" {
|
||||
duplicate := false
|
||||
for i := range routes {
|
||||
if routes[i].Method == "USE" && routes[i].Name == app.stack[m][r].Name {
|
||||
duplicate = true
|
||||
}
|
||||
}
|
||||
if !duplicate {
|
||||
routes = append(routes, app.stack[m][r])
|
||||
}
|
||||
} else {
|
||||
routes = append(routes, app.stack[m][r])
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sort routes by stack position
|
||||
|
|
|
@ -46,6 +46,7 @@ type Route struct {
|
|||
routeParams []string // Case sensitive param keys
|
||||
|
||||
// Public fields
|
||||
Name string // Name of first handler used in route
|
||||
Path string // Original registered route path
|
||||
Method string // HTTP method
|
||||
Handlers []Handler // Ctx handlers
|
||||
|
@ -319,6 +320,10 @@ func (app *App) registerStatic(prefix, root string, config ...Static) *Route {
|
|||
}
|
||||
|
||||
func (app *App) addRoute(method string, route *Route) {
|
||||
// Give name to route if not defined
|
||||
if route.Name == "" && len(route.Handlers) > 0 {
|
||||
route.Name = utils.FunctionName(route.Handlers[0])
|
||||
}
|
||||
// Get unique HTTP method indentifier
|
||||
m := methodINT[method]
|
||||
// Add route to the stack
|
||||
|
|
Loading…
Reference in New Issue