Skip to content

refactor(server)!: remove Server.Audit, use Router.Use() middleware - #147

Merged
benitogf merged 2 commits into
mainfrom
refactor/router-use-replaces-audit
Jun 10, 2026
Merged

refactor(server)!: remove Server.Audit, use Router.Use() middleware#147
benitogf merged 2 commits into
mainfrom
refactor/router-use-replaces-audit

Conversation

@benitogf

Copy link
Copy Markdown
Owner

Summary

Closes #146Server.Audit and its companions are gone; consumers gate
requests by registering middleware on server.Router.Use(...).

  • The bool-returning Server.Audit hook, AuditHandler, and the
    explorer's AuditFunc are removed from the public API.
  • Built-in REST handlers, WebSocket upgrades, custom endpoints, proxy
    routes, and the explorer UI all dispatch through the standard
    gorilla/mux middleware chain — one extension point, no parallel
    mechanisms.
  • The JWT auth sample and the static-routes/filters sample demonstrate
    the middleware-based pattern.
  • An internal doc comment that claimed Router.Use() middlewares were
    silently dropped on dispatch is corrected — gorilla/mux's Match
    builds 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

  • The sample directory name samples/static_routes_filters_audit/ is
    intentionally 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.
  • The exported ErrNotAuthorized sentinel is kept for consumers who
    want 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.
  • No production code path still references Server.Audit,
    AuditHandler, or AuditFunc.
  • The JWT sample boots and rejects unauthenticated requests to
    /data/* while allowing /register and /authorize.
  • The static-routes sample rejects requests without the
    X-API-Key: secret header on every dispatched path (REST,
    explorer UI, custom endpoints).
  • WebSocket subscriptions are gated by the middleware chain — a
    deny-all middleware refuses the upgrade cleanly with 401, no
    half-upgraded connections.

🤖 Generated with Claude Code

root and others added 2 commits June 10, 2026 13:24
…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 CBosch101 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Match builds the middleware chain into match.Handler when MatchErr == nil, and syncRouter.ServeHTTP (ooo.go:65-88) dispatches match.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: Match only wraps when MatchErr == nil, and syncRouter.ServeHTTP handles 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): clock is reached only via ClockFunc inside 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 -race are clean on the affected packages. The LimitBody short-circuit note (rest.go) is updated correctly to state deny middleware must not call next.

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

@benitogf
benitogf merged commit ad5c43e into main Jun 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace Server.Audit with Router.Use() middleware chain

2 participants