Skip to content

Commit

Permalink
fix handler order in routing
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Feb 22, 2025
1 parent 249557c commit e796099
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ func (*App) copyRoute(route *Route) *Route {
}

func (app *App) register(methods []string, pathRaw string, group *Group, handlers ...Handler) {
// A route requires atleast one ctx handler
if group == nil && len(handlers) == 0 {
panic(fmt.Sprintf("missing handler in route: %s\n", pathRaw))
// A regular route requires at least one ctx handler
isMount := group != nil && group.app != app
if len(handlers) == 0 && !isMount {
panic(fmt.Sprintf("missing handler/middleware in route: %s\n", pathRaw))

Check warning on line 325 in router.go

View check run for this annotation

Codecov / codecov/patch

router.go#L325

Added line #L325 was not covered by tests
}

// Precompute path normalization ONCE
Expand Down Expand Up @@ -349,11 +350,6 @@ func (app *App) register(methods []string, pathRaw string, group *Group, handler
panic(fmt.Sprintf("add: invalid http method %s\n", method))
}

isMount := group != nil && group.app != app
if len(handlers) == 0 && !isMount {
panic(fmt.Sprintf("missing handler/middleware in route: %s\n", pathRaw))
}

isUse := method == methodUse
isStar := pathClean == "/*"
isRoot := pathClean == "/"
Expand Down

0 comments on commit e796099

Please sign in to comment.