A powerful HTTP router and URL matcher for building Go web servers with advanced routing features.
Gorilla/mux is a feature-rich HTTP request multiplexer (router) for the Go programming language. It allows developers to define complex routing rules for web servers, matching requests based on URL patterns, headers, methods, and other conditions. It solves the need for more advanced routing beyond the standard library's basic multiplexer.
Go developers building web servers, REST APIs, or microservices that require sophisticated routing, middleware integration, or serving both static assets and dynamic endpoints.
Developers choose gorilla/mux for its extensive feature set while maintaining full compatibility with Go's `net/http` package. Its subrouter support, route variables, and middleware ecosystem make it a robust alternative to simpler routers.
Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports matching based on URL host, path, headers, query values, HTTP methods, and custom matchers, enabling complex routing logic that the standard http.ServeMux lacks.
Allows dynamic routing with path variables and regex patterns, plus subrouters for grouping routes with shared conditions, optimizing matching and improving code organization as shown in the README examples.
Fully compatible with Go's http.Handler interface, making it easy to integrate middleware chains for logging, authentication, or CORS, with clear examples in the README.
Provides built-in support for serving static files and single-page applications (SPAs) alongside API routes, with detailed code snippets for handling client-side routing fallbacks.
The CORSMethodMiddleware only sets Access-Control-Allow-Methods; developers must manually handle other CORS headers like Access-Control-Allow-Origin, as admitted in the README, adding extra boilerplate.
The rich feature set introduces measurable overhead compared to barebones routers, which can impact latency in ultra-high-throughput scenarios where every microsecond counts.
Routes are matched in the order they are added, so misordering (e.g., catch-all routes before specific ones) can cause bugs, requiring careful management that isn't needed in some competing routers.