refactor(server)!: remove Server.Audit, use Router.Use() middleware - #147
Merged
Conversation
…gate BREAKING: deletes Server.Audit, AuditHandler, and ui.Handler.AuditFunc. Consumers gate requests by registering middleware via server.Router.Use(...); gorilla/mux's Match builds the chain into the matched handler so REST, WebSocket upgrades, custom Endpoints, proxy routes, and the explorer UI all run after the middleware. Samples and tests are rewritten to use the new pattern. The misleading syncRouter doc comment claiming middlewares were "not fanned out" is corrected to describe actual behavior. Closes #146 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Self-review surfaced four doc surfaces that still described the removed hook. README's feature list, the README "Audit" section, the Server struct godoc, and the sample README all now describe the Router.Use() middleware pattern. Also clarifies LimitBody's middleware-ordering invariant and notes that unmatched-path responses skip the chain. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
CBosch101
approved these changes
Jun 10, 2026
CBosch101
left a comment
There was a problem hiding this comment.
Clean breaking refactor: Server.Audit / AuditHandler / ui.Handler.AuditFunc are gone, request gating moves to Router.Use() middleware. The central correctness claim holds — verified, not assumed.
Verified
- The "middleware fans out" claim is real for this dispatch path: gorilla/mux (v1.8.1)
Router.Matchbuilds the middleware chain intomatch.HandlerwhenMatchErr == nil, andsyncRouter.ServeHTTP(ooo.go:65-88) dispatchesmatch.Handler— so REST, WebSocket upgrades, custom Endpoints, proxy routes, and the explorer UI are all gated by one chain. The corrected doc comment (ooo.go:46-52, replacing the old "not fanned out" claim) matches actual behavior. - 404/405 correctly skip the chain:
Matchonly wraps whenMatchErr == nil, andsyncRouter.ServeHTTPhandles method-mismatch/not-found before invoking any handler (ooo.go:79-86) — consistent with the README and the doc comment. - The clock WS path is safe after dropping its inline check (clock.go):
clockis reached only viaClockFuncinside the explorer handler (ui/ui.go:159-160), which is route-registered at/and therefore middleware-wrapped. - No lingering references to the removed API in non-test code; the renamed/rewritten gating tests pass, and
go build/go vet/go test -raceare clean on the affected packages. The LimitBody short-circuit note (rest.go) is updated correctly to state deny middleware must not callnext.
No blockers. The breaking removal is intentional and the migration is mechanical (set a Router.Use(...) middleware instead of Server.Audit), shown in both samples and the README.
🤖 Generated with Claude Code
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.
Summary
Closes #146 —
Server.Auditand its companions are gone; consumers gaterequests by registering middleware on
server.Router.Use(...).Server.Audithook,AuditHandler, and theexplorer's
AuditFuncare removed from the public API.routes, and the explorer UI all dispatch through the standard
gorilla/mux middleware chain — one extension point, no parallel
mechanisms.
the middleware-based pattern.
Router.Use()middlewares weresilently dropped on dispatch is corrected — gorilla/mux's
Matchbuilds the chain into the matched handler before returning, so
middleware already fans out today. The PR removes the redundant
parallel mechanism rather than adding new machinery.
Known non-blockers folded into the PR
samples/static_routes_filters_audit/isintentionally left in place — the heading and code inside have been
updated, but renaming the directory would break any external links.
Future cosmetic rename is fair game.
ErrNotAuthorizedsentinel is kept for consumers whowant to return it from their own middleware. Drop it later if no
external consumer adopts it.
Test plan
go test ./...passes (verified locally, race + non-race).go vet ./...clean.Server.Audit,AuditHandler, orAuditFunc./data/*while allowing/registerand/authorize.X-API-Key: secretheader on every dispatched path (REST,explorer UI, custom endpoints).
deny-all middleware refuses the upgrade cleanly with 401, no
half-upgraded connections.
🤖 Generated with Claude Code