gorilla/mux

Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍

View on GitHub ↗Jump to charts ↓

Summary Information

Updated 40 minutes ago
Added to GitGenius on April 8th, 2021
Created on October 2nd, 2012
Open Issues & Pull Requests: 39 (+0)
Number of forks: 1,892
Total Stargazers: 21,839 (+0)
Total Subscribers: 297 (+0)

Repository Insights (GitGenius)

Median issue/PR response: 17.3 days
Mean response time: 423.2 days
90th percentile: 1899.4 days
Tracked items: 23

How this project is maintained

Around half of the issues opened in the past year never receive a reply. 100% of open issues come from outside the core team, so the backlog reflects real-world use rather than internal planning. Only 5% of issues opened in the past year have been closed.

Charts & Analytics

Fetching additional details & charts...

Issue Activity (beta)

Open issues: 24
New in 7 days: 0
Closed in 7 days: 0
Avg open age: 908 days
Stale 30+ days: 24
Stale 90+ days: 22

Recent activity

Opened in 7 days: 0
Closed in 7 days: 0
Comments in 7 days: 0
Events in 7 days: 0

Top labels

  • question (141)
  • stale (96)
  • bug (88)
  • enhancement (32)
  • help wanted (23)
  • documentation (21)
  • wontfix (11)
  • proposal (3)

Most active issues this week

No issue events were indexed in the last 7 days.

Detailed Description

Gorilla/mux is a powerful HTTP router and URL matcher for Go web servers that implements the http.Handler interface, making it compatible with Go's standard http.ServeMux. The package provides a request router and dispatcher that matches incoming HTTP requests against registered routes and calls the appropriate handler. The name mux stands for HTTP request multiplexer, and it serves as a core component for building RESTful APIs and web applications in Go.

The router supports matching requests based on multiple criteria including URL host, path, path prefix, schemes, header values, query values, and HTTP methods. Routes can also use custom matcher functions for more complex matching logic. URL variables can be defined using the format {name} or {name:pattern}, where pattern is an optional regular expression. This allows developers to extract parameters from URLs and access them through the mux.Vars() function. The router also supports regex matching for headers, enabling content-type based routing and similar use cases.

One of the standout features is the ability to build or reverse registered URLs, which helps maintain references to resources throughout an application. Routes can be named, and their URLs can be reconstructed by passing key-value pairs for route variables. The router also provides methods like URLHost() and URLPath() for building specific components of URLs, and GetVarNames() to discover required variables for a given route.

Subrouting is another powerful capability that allows developers to group routes sharing common conditions like a host, path prefix, or other attributes. Nested routes are only tested if the parent route matches, which optimizes request matching and enables the creation of domain or path namespaces. This feature is particularly useful for organizing complex applications with multiple logical sections.

The package includes middleware support through the standard MiddlewareFunc type, allowing developers to add request logging, header manipulation, response writer hijacking, and authentication. Middlewares are executed in the order they are added if a match is found, including subrouters. The router also provides CORSMethodMiddleware to simplify setting the Access-Control-Allow-Methods response header for CORS requests.

Additional features include a Walk function for visiting all registered routes, support for graceful shutdown of HTTP servers, and straightforward testing capabilities. The router can serve static files using PathPrefix() and can serve single-page applications alongside API endpoints.