Conversation
We do not need to register another middleware for this if we already have `type middleware` (which also should be renamed to clarify that it is the outermost middleware instead of just _any_ middleware).
Also clarify its role by adding code comments.
Right now, this change is pretty nonsensical because there are no other options, but the next commit will add a non-gorilla/mux option.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
EndpointNamer now executes before routing, breaking route-context-based endpoint labeling.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds gg/pathrouter support alongside gorilla/mux, prioritizing lightweight TryHandler routing.
Changes:
- Adds lazy mux creation and ordered
TryHandlerdispatch. - Refactors middleware composition and routing tests.
- Upgrades
go.xyrillian.de/ggto v1.17.0.
| File | Description |
|---|---|
httpapi/api.go |
Adds the TryHandler API. |
httpapi/compose.go |
Dispatches try-handlers before mux. |
httpapi/middleware.go |
Refactors instrumentation middleware. |
httpapi/httpapi_test.go |
Tests both routing mechanisms. |
go.mod |
Updates the gg dependency. |
go.sum |
Updates dependency checksums. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
I cannot find any uses of it in all known downstream users. If there are
any that I could not find, they can be replaced by a pseudo-API like this:
```go
func (endpointNamer) AddTo(c *httpapi.Composer) {
c.Router().Use(func (next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
IdentifyEndpoint(r, mux.CurrentRoute(r).GetName()) // replace as appropriate
next.ServeHTTP(w, r)
})
}
}
```
I chose not to retain EndpointNamer because its semantics conflict with
the existence of TryHandlers into which we cannot introspect.
EndpointNamer is specified as executing after gorilla/mux has made a routing
decision, so we cannot run it in any of the middlewares (before the
routing decision). But that's the only places where we can interact with
a request that ends up being answered by a TryHandler.
It would only have been possible to keep EndpointNamer, but document it
as specifically only applying to gorilla/mux routes, which is a weird
unexpected restriction. This dependency should rather be made explicit
by using a pseudo-API as in the code snippet above.
majewsky
force-pushed
the
httpapi-pathrouter
branch
from
October 5, 2026 11:15
814629d to
4d56f00
Compare
Merging this branch will decrease overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
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.

See sapcc/keppel#781 for reasoning: To support gg/pathrouter, this extends httpapi.Composer to allow bypassing the main gorilla/mux router and registering TryHandlers directly. If there are any, request routing will try them first before going into the gorilla/mux router (which is important both because the gorilla/mux router forces a 404 response when it does not match anything, so any other option must be exhausted first, and also because going into a gorilla/mux router means paying the price of matching regexes for the routes contained within).
This is split into several small commits that I recommend reviewing individually.