Skip to content

Replace gorilla/mux with Go 1.22 stdlib ServeMux in test server#4955

Open
pietern wants to merge 1 commit intomainfrom
go1.22-replace-gorilla-mux-with-stdlib-servemux
Open

Replace gorilla/mux with Go 1.22 stdlib ServeMux in test server#4955
pietern wants to merge 1 commit intomainfrom
go1.22-replace-gorilla-mux-with-stdlib-servemux

Conversation

@pietern
Copy link
Copy Markdown
Contributor

@pietern pietern commented Apr 13, 2026

Summary

  • Remove the gorilla/mux dependency by switching libs/testserver to Go 1.22's enhanced net/http.ServeMux, which added method-based routing ("GET /items/{id}"), path wildcards ({id}), and rest wildcards ({path...}) — the same features we used gorilla for. See the Go 1.22 release notes.
  • Replace gorilla's {path:.*} regex wildcards with stdlib {path...} rest wildcards, and mux.Vars(r) with r.PathValue().
  • Exact (non-wildcard) paths are dispatched via a map lookup before reaching ServeMux. This avoids a ServeMux limitation where registering method-specific exact paths alongside method-specific wildcard patterns panics due to Go's implicit GET→HEAD handling creating unresolvable precedence. When an exact path has no handler for the request method, it falls through to ServeMux where a wildcard handler can serve it (e.g., a stub registers GET /exact/path, but HEAD falls through to a wildcard HEAD handler).
  • Wildcard patterns in test.toml stubs must now use the same placeholder names as the default handlers they coexist with — ServeMux panics on structurally identical patterns with different wildcard names. Two stubs updated: {name}{full_name}.

Test plan

  • Unit tests pass (libs/testserver, bundle/direct/dresources, acceptance/internal)
  • Acceptance selftests pass
  • Full CI

This pull request was AI-assisted by Isaac.

Go 1.22 added method-based routing ("GET /items/{id}"), path wildcards
({id}), and rest wildcards ({path...}) to net/http.ServeMux, which
directly replaces the features we used gorilla/mux for. This removes the
gorilla/mux dependency from go.mod and NOTICE.

Exact (non-wildcard) paths are dispatched via a map lookup before
reaching ServeMux. This avoids a ServeMux limitation where registering
e.g. "GET /exact/path" alongside "HEAD /prefix/{path...}" panics because
Go's implicit GET→HEAD handling creates an unresolvable precedence
conflict. When an exact path is registered for one method but a request
arrives for a different method, it falls through to ServeMux where the
wildcard handler serves it.

Wildcard patterns in test stubs (test.toml) must use the same
placeholder names as the default handlers they coexist with. ServeMux
panics on structurally identical patterns with different names (e.g.
{name} vs {full_name}). Two test stubs are updated accordingly.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown

Approval status: pending

/acceptance/bundle/ - needs approval

Files: acceptance/bundle/invariant/test.toml, acceptance/bundle/resources/synced_database_tables/basic/test.toml
Suggested: @denik
Also eligible: @shreyas-goenka, @andrewnester, @anton-107, @janniklasrose, @lennartkats-db

General files (require maintainer)

Files: NOTICE, acceptance/internal/prepare_server.go, go.mod, go.sum, libs/testserver/handlers.go, libs/testserver/server.go
Based on git history:

  • @denik -- recent work in libs/testserver/, acceptance/bundle/invariant/, acceptance/internal/

Any maintainer (@andrewnester, @anton-107, @denik, @shreyas-goenka, @simonfaltum, @renaudhartert-db) can approve all areas.
See OWNERS for ownership rules.

@pietern pietern requested a review from denik April 13, 2026 21:38
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.

1 participant