gorilla/mux was the default Go router for a decade. The Gorilla project was archived in December 2022, briefly leaving every service depending on it in awkward territory, and was revived in late 2023 under a new community maintainership. Meanwhile Go 1.22 added pattern-matching (path parameters, method-bound routes) to the stdlib net/http ServeMux. This article is the operator’s decision tree: stay, move to stdlib, or migrate to chi.
How to verify
Check whether your project still uses gorilla/mux and what it actually needs from it:
go list -m all | grep gorilla/mux
grep -rn 'github.com/gorilla/mux' .
grep -rn 'mux.Vars\|mux.Router' .
grep -rn 'Subrouter\|HandleFunc\|UseEncodedPath\|StrictSlash' .
The features you exercise determine the migration path. A project that only uses mux.NewRouter().HandleFunc(...) and mux.Vars(r) can move to stdlib in 1.22. A project that uses subrouters, host matchers, or StrictSlash keeps more semantics by moving to chi.
What’s happening
Three router families live in modern Go:
- stdlib
net/http(Go 1.22+): supports method-prefixed patterns (GET /users/{id}), path wildcards (/static/{path...}), and per-host routing. No middleware concept, no subrouters, no regex on params. Zero dependencies, maintained by the Go core team. chi(github.com/go-chi/chi/v5): standalone router compatible withhttp.Handler. Provides middleware chains, subrouters viaRoute/Mount, URL param helpers, and routes-with-context propagation. Actively maintained, single dependency, idiomatic Go style.gorilla/mux: revived undergorilla.github.io/mux. Same API as before. Supports host matching, header matching, scheme matching, full regex on path params, andStrictSlash. Maintenance is community-driven.
The community signal in 2024-26 is that chi has more momentum than the revived gorilla/mux. New code we audit overwhelmingly uses chi or stdlib; gorilla appears mostly in legacy code.
Decision
Pick by which features you actually use:
| You need | Use |
|---|---|
| Only method + path patterns | stdlib (Go 1.22+) |
| Middleware chains, subrouters, ergonomic params | chi |
Host matching, header matching, regex paths, StrictSlash | gorilla/mux (revived) |
A net-new service has no good reason to start with gorilla — start with stdlib and adopt chi when you need middleware composition.
The procedure
-
Migrating
mux.Vars(r)to Go 1.22 stdlib.// gorilla/mux r := mux.NewRouter() r.HandleFunc("/users/{id}", getUser).Methods("GET") func getUser(w http.ResponseWriter, r *http.Request) { id := mux.Vars(r)["id"] // ... }Becomes:
// stdlib net/http (Go 1.22+) mux := http.NewServeMux() mux.HandleFunc("GET /users/{id}", getUser) func getUser(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") }r.PathValuereplacesmux.Vars. Method binding is now part of the pattern. -
Migrating to chi. A drop-in replacement with familiar shape:
import "github.com/go-chi/chi/v5" r := chi.NewRouter() r.Use(middleware.Logger) r.Use(middleware.Recoverer) r.Route("/api", func(r chi.Router) { r.Get("/users/{id}", getUser) r.Post("/users", createUser) }) func getUser(w http.ResponseWriter, r *http.Request) { id := chi.URLParam(r, "id") }chi.URLParamreplacesmux.Vars. Subrouters withRoute/MountreplaceSubrouter. -
Migrating middleware. Gorilla’s
r.Use(...)middlewares are purehttp.Handlerdecorators, so they port directly:func auth(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if !checkToken(r) { http.Error(w, "unauthorized", 401); return } next.ServeHTTP(w, r) }) }Same function works with
chi.Router.Use(auth), with stdlib via a single wrapping function, and with gorillar.Use(auth). -
Handling features stdlib does not have. If you depended on:
- Host matching: stdlib supports
Host()patterns since 1.22 (mux.Handle("api.example.com/", ...)). - Header matching: not in stdlib or chi. Roll into middleware.
- Regex on path params: not in stdlib. Chi only supports
{name:[0-9]+}. Gorilla retains full regex. StrictSlash: stdlib has trailing-slash normalization built into its pattern matcher; chi hasmiddleware.StripSlashesandmiddleware.RedirectSlashes. Behavior is not identical to gorilla.
- Host matching: stdlib supports
-
Run the migration as a vet-staged change.
go test ./... # baseline # change one handler group at a time go test ./... # http integration tests against the change go run ./cmd/api & sleep 1; curl -i localhost:8080/users/42; kill %1Avoid a big-bang migration; routers touch every endpoint.
-
Keep
net/http.Handlereverywhere. All three options compose aroundhttp.Handlerandhttp.HandlerFunc. Code that takes/returns those is portable across routers — write your business handlers againsthttp.Handler, not against a router-specific type.
Common pitfalls
- Gorilla’s
mux.Routeris anhttp.Handlerbut not interchangeable with chi’schi.Router. Adapter code that depends on the concrete type breaks. Refactor tohttp.Handler. r.PathValue("id")returns empty string for missing keys, not error. Add explicit validation.- Go 1.22 stdlib patterns have a precedence model. Specific patterns win over general ones (
/users/meover/users/{id}). Test pairs that overlap. chi’s subrouter does not inherit middleware unless mounted explicitly. Read the docs onRoutevsMountvsGroup— same surface, different propagation rules.- Regex matching is the silent migration killer. Audit
r.HandleFunc("/{slug:[a-z0-9-]+}", ...)first — neither stdlib nor chi supports gorilla’s full regex.
Stack Harbor migrates legacy gorilla/mux services to chi (or stdlib for small services) as part of long-term operations engagements — see golang-chi-router-pattern for the target pattern. The migration fits inside our managed operations practice when a dependency goes out of active maintenance.