(methods []string, matchFunc func(r *Route) bool)
| 565 | } |
| 566 | |
| 567 | func (app *App) deleteRoute(methods []string, matchFunc func(r *Route) bool) { |
| 568 | if len(methods) == 0 { |
| 569 | methods = app.config.RequestMethods |
| 570 | } |
| 571 | |
| 572 | app.mutex.Lock() |
| 573 | defer app.mutex.Unlock() |
| 574 | |
| 575 | removedUseRoutes := make(map[string]struct{}) |
| 576 | |
| 577 | for _, method := range methods { |
| 578 | // Uppercase HTTP methods |
| 579 | method = utilsstrings.ToUpper(method) |
| 580 | |
| 581 | // Get unique HTTP method identifier |
| 582 | m := app.methodInt(method) |
| 583 | if m == -1 { |
| 584 | continue // Skip invalid HTTP methods |
| 585 | } |
| 586 | |
| 587 | for i := len(app.stack[m]) - 1; i >= 0; i-- { //nolint:modernize // false positive |
| 588 | route := app.stack[m][i] |
| 589 | if !matchFunc(route) { |
| 590 | continue // Skip if route does not match |
| 591 | } |
| 592 | |
| 593 | app.stack[m] = append(app.stack[m][:i], app.stack[m][i+1:]...) |
| 594 | app.hasRoutesRefreshed = true |
| 595 | |
| 596 | // Decrement global handler count. In middleware routes, only decrement once |
| 597 | if _, ok := removedUseRoutes[route.path]; (route.use && slices.Equal(methods, app.config.RequestMethods) && !ok) || !route.use { |
| 598 | if route.use { |
| 599 | removedUseRoutes[route.path] = struct{}{} |
| 600 | } |
| 601 | |
| 602 | atomic.AddUint32(&app.handlersCount, ^uint32(len(route.Handlers)-1)) //nolint:gosec // G115 - handler count is always small |
| 603 | } |
| 604 | |
| 605 | if method == MethodGet && !route.use && !route.mount { |
| 606 | app.pruneAutoHeadRouteLocked(route.path) |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // pruneAutoHeadRouteLocked removes an automatically generated HEAD route so a |
| 613 | // later explicit registration can take its place without duplicating handler |
no test coverage detected