fix(group): register auto 404 routes only once on Use#3048
Closed
Solaris-star wants to merge 1 commit into
Closed
Conversation
Group.Use always called RouteNotFound for "" and "/*" whenever middleware was present. A second Use() (or Group(..., mw) followed by Use) re-added the same routes and panicked when AllowOverwritingRoute is false. Only auto-register the catch-all 404 routes the first time middleware is attached to the group. Fixes labstack#3047
Contributor
|
Thanks, closing, #3049 implemented a little bit different approach |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
After #2996,
Group.Useauto-registersRouteNotFoundcatch-alls so group middleware still runs on 404s. It did that on everyUse()call.With
AllowOverwritingRoute: false(or whenever duplicate routes are rejected), a secondUsepanics:Repro patterns from #3047:
Fix
Only auto-register the 404 routes the first time the group gains middleware (
hadMiddlewarewas empty before append). SubsequentUsecalls only append middleware.Tests
go test ./... -count=1Added
TestGroup_UseMultipleTimesDoesNotPanic.Linked Issue
Closes #3047