(method string, route *Route)
| 712 | } |
| 713 | |
| 714 | func (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 | |
| 746 | func (app *App) ensureAutoHeadRoutes() { |
| 747 | app.mutex.Lock() |
no test coverage detected