mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 08:13:08 +00:00
🗑️ Remove pos from Route
Co-Authored-By: RW <renewerner87@googlemail.com> Co-Authored-By: kiyon <kiyonlin@users.noreply.github.com>
This commit is contained in:
parent
e4b345b35c
commit
396b6ddebc
14
router.go
14
router.go
@ -37,7 +37,6 @@ type Router interface {
|
|||||||
// Route is a struct that holds all metadata for each registered handler
|
// Route is a struct that holds all metadata for each registered handler
|
||||||
type Route struct {
|
type Route struct {
|
||||||
// Data for routing
|
// Data for routing
|
||||||
pos int // Position in stack
|
|
||||||
use bool // USE matches path prefixes
|
use bool // USE matches path prefixes
|
||||||
star bool // Path equals '*'
|
star bool // Path equals '*'
|
||||||
root bool // Path equals '/'
|
root bool // Path equals '/'
|
||||||
@ -196,6 +195,10 @@ func (app *App) register(method, pathRaw string, handlers ...Handler) Route {
|
|||||||
Method: method,
|
Method: method,
|
||||||
Handlers: handlers,
|
Handlers: handlers,
|
||||||
}
|
}
|
||||||
|
// Increment global handler count
|
||||||
|
app.mutex.Lock()
|
||||||
|
app.handlerCount += len(handlers)
|
||||||
|
app.mutex.Unlock()
|
||||||
// Middleware route matches all HTTP methods
|
// Middleware route matches all HTTP methods
|
||||||
if isUse {
|
if isUse {
|
||||||
// Add route to all HTTP methods stack
|
// Add route to all HTTP methods stack
|
||||||
@ -309,6 +312,10 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Route {
|
|||||||
Path: prefix,
|
Path: prefix,
|
||||||
Handlers: []Handler{handler},
|
Handlers: []Handler{handler},
|
||||||
}
|
}
|
||||||
|
// Increment global handler count
|
||||||
|
app.mutex.Lock()
|
||||||
|
app.handlerCount++
|
||||||
|
app.mutex.Unlock()
|
||||||
// Add route to stack
|
// Add route to stack
|
||||||
app.addRoute(MethodGet, &route)
|
app.addRoute(MethodGet, &route)
|
||||||
// Add HEAD route
|
// Add HEAD route
|
||||||
@ -327,11 +334,6 @@ func (app *App) addRoute(method string, route *Route) {
|
|||||||
preRoute := app.stack[m][l-1]
|
preRoute := app.stack[m][l-1]
|
||||||
preRoute.Handlers = append(preRoute.Handlers, route.Handlers...)
|
preRoute.Handlers = append(preRoute.Handlers, route.Handlers...)
|
||||||
} else {
|
} else {
|
||||||
// Increment global route position
|
|
||||||
app.mutex.Lock()
|
|
||||||
app.routesCount++
|
|
||||||
app.mutex.Unlock()
|
|
||||||
route.pos = app.routesCount
|
|
||||||
route.Method = method
|
route.Method = method
|
||||||
// Add route to the stack
|
// Add route to the stack
|
||||||
app.stack[m] = append(app.stack[m], route)
|
app.stack[m] = append(app.stack[m], route)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user