MCPcopy
hub / github.com/gofiber/fiber / addRoute

Method addRoute

router.go:714–744  ·  view source on GitHub ↗
(method string, route *Route)

Source from the content-addressed store, hash-verified

712}
713
714func (app *App) addRoute(method string, route *Route) {
715 app.mutex.Lock()
716 defer app.mutex.Unlock()
717
718 // Get unique HTTP method identifier
719 m := app.methodInt(method)
720
721 if method == MethodHead && !route.mount && !route.use {
722 app.pruneAutoHeadRouteLocked(route.path)
723 }
724
725 // prevent identically route registration
726 l := len(app.stack[m])
727 if l > 0 && app.stack[m][l-1].Path == route.Path && route.use == app.stack[m][l-1].use && !route.mount && !app.stack[m][l-1].mount {
728 preRoute := app.stack[m][l-1]
729 preRoute.Handlers = append(preRoute.Handlers, route.Handlers...)
730 } else {
731 route.Method = method
732 // Add route to the stack
733 app.stack[m] = append(app.stack[m], route)
734 app.hasRoutesRefreshed = true
735 }
736
737 // Execute onRoute hooks & change latestRoute if not adding mounted route
738 if !route.mount {
739 app.latestRoute = route
740 if err := app.hooks.executeOnRouteHooks(route); err != nil {
741 panic(err)
742 }
743 }
744}
745
746func (app *App) ensureAutoHeadRoutes() {
747 app.mutex.Lock()

Callers 1

registerMethod · 0.95

Calls 5

methodIntMethod · 0.95
executeOnRouteHooksMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected