mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-22 15:24:38 +00:00
Merge pull request #661 from ReneWerner87/master
💉 Sync route method metadata
This commit is contained in:
commit
0cbe432ee0
7
app.go
7
app.go
@ -415,15 +415,12 @@ func (app *App) Routes() []*Route {
|
||||
stackLoop:
|
||||
for r := range app.stack[m] {
|
||||
// Don't duplicate USE routesCount
|
||||
if app.stack[m][r].Method == methodUse {
|
||||
if app.stack[m][r].use {
|
||||
for i := range routes {
|
||||
if routes[i].Method == methodUse && routes[i].Path == app.stack[m][r].Path {
|
||||
if routes[i].use && routes[i].Path == app.stack[m][r].Path {
|
||||
continue stackLoop
|
||||
}
|
||||
}
|
||||
// Ignore HEAD routes handling GET routesCount
|
||||
} else if m != methodInt(app.stack[m][r].Method) {
|
||||
continue
|
||||
}
|
||||
routes = append(routes, app.stack[m][r])
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ func Test_App_Routes(t *testing.T) {
|
||||
app.Get("/Get", h)
|
||||
app.Head("/Head", h)
|
||||
app.Post("/post", h)
|
||||
utils.AssertEqual(t, 4, len(app.Routes()))
|
||||
utils.AssertEqual(t, 5, len(app.Routes()))
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=Benchmark_App_Routes -benchmem -count=4
|
||||
|
@ -145,7 +145,7 @@ func (app *App) register(method, pathRaw string, handlers ...Handler) Route {
|
||||
// Uppercase HTTP methods
|
||||
method = utils.ToUpper(method)
|
||||
// Check if the HTTP method is valid unless it's USE
|
||||
if methodInt(method) == -1 {
|
||||
if method != methodUse && methodInt(method) == -1 {
|
||||
panic(fmt.Sprintf("add: invalid http method %s\n", method))
|
||||
}
|
||||
// A route requires atleast one ctx handler
|
||||
@ -332,6 +332,7 @@ func (app *App) addRoute(method string, route *Route) {
|
||||
app.routesCount++
|
||||
app.mutex.Unlock()
|
||||
route.pos = app.routesCount
|
||||
route.Method = method
|
||||
// Add route to the stack
|
||||
app.stack[m] = append(app.stack[m], route)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user