{"id":8639425,"name":"github.com/2lambda123/mux","ecosystem":"go","description":"Package mux implements a request router and dispatcher.\n\nThe name mux stands for \"HTTP request multiplexer\". Like the standard\nhttp.ServeMux, mux.Router matches incoming requests against a list of\nregistered routes and calls a handler for the route that matches the URL\nor other conditions. The main features are:\n\nLet's start registering a couple of URL paths and handlers:\n\nHere we register three routes mapping URL paths to handlers. This is\nequivalent to how http.HandleFunc() works: if an incoming request URL matches\none of the paths, the corresponding handler is called passing\n(http.ResponseWriter, *http.Request) as parameters.\n\nPaths can have variables. They are defined using the format {name} or\n{name:pattern}. If a regular expression pattern is not defined, the matched\nvariable will be anything until the next slash. For example:\n\nGroups can be used inside patterns, as long as they are non-capturing (?:re). For example:\n\nThe names are used to create a map of route variables which can be retrieved\ncalling mux.Vars():\n\nNote that if any capturing groups are present, mux will panic() during parsing. To prevent\nthis, convert any capturing groups to non-capturing, e.g. change \"/{sort:(asc|desc)}\" to\n\"/{sort:(?:asc|desc)}\". This is a change from prior versions which behaved unpredictably\nwhen capturing groups were present.\n\nAnd this is all you need to know about the basic usage. More advanced options\nare explained below.\n\nRoutes can also be restricted to a domain or subdomain. Just define a host\npattern to be matched. They can also have variables:\n\nThere are several other matchers that can be added. To match path prefixes:\n\n...or HTTP methods:\n\n...or URL schemes:\n\n...or header values:\n\n...or query values:\n\n...or to use a custom matcher function:\n\n...and finally, it is possible to combine several matchers in a single route:\n\nSetting the same matching conditions again and again can be boring, so we have\na way to group several routes that share the same requirements.\nWe call it \"subrouting\".\n\nFor example, let's say we have several URLs that should only match when the\nhost is \"www.example.com\". Create a route for that host and get a \"subrouter\"\nfrom it:\n\nThen register routes in the subrouter:\n\nThe three URL paths we registered above will only be tested if the domain is\n\"www.example.com\", because the subrouter is tested first. This is not\nonly convenient, but also optimizes request matching. You can create\nsubrouters combining any attribute matchers accepted by a route.\n\nSubrouters can be used to create domain or path \"namespaces\": you define\nsubrouters in a central place and then parts of the app can register its\npaths relatively to a given subrouter.\n\nThere's one more thing about subroutes. When a subrouter has a path prefix,\nthe inner routes use it as base for their paths:\n\nNote that the path provided to PathPrefix() represents a \"wildcard\": calling\nPathPrefix(\"/static/\").Handler(...) means that the handler will be passed any\nrequest that matches \"/static/*\". This makes it easy to serve static files with mux:\n\nNow let's see how to build registered URLs.\n\nRoutes can be named. All routes that define a name can have their URLs built,\nor \"reversed\". We define a name calling Name() on a route. For example:\n\nTo build a URL, get the route and call the URL() method, passing a sequence of\nkey/value pairs for the route variables. For the previous route, we would do:\n\n...and the result will be a url.URL with the following path:\n\nThis also works for host and query value variables:\n\nAll variables defined in the route are required, and their values must\nconform to the corresponding patterns. These requirements guarantee that a\ngenerated URL will always match a registered route -- the only exception is\nfor explicitly defined \"build-only\" routes which never match.\n\nRegex support also exists for matching Headers within a route. For example, we could do:\n\n...and the route will match both requests with a Content-Type of `application/json` as well as\n`application/text`\n\nThere's also a way to build only the URL host or path for a route:\nuse the methods URLHost() or URLPath() instead. For the previous route,\nwe would do:\n\nAnd if you use subrouters, host and path defined separately can be built\nas well:\n\nMux supports the addition of middlewares to a Router, which are executed in the order they are added if a match is found, including its subrouters. Middlewares are (typically) small pieces of code which take one request, do something with it, and pass it down to another middleware or the final handler. Some common use cases for middleware are request logging, header manipulation, or ResponseWriter hijacking.\n\nTypically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed to it, and then calls the handler passed as parameter to the MiddlewareFunc (closures can access variables from the context where they are created).\n\nA very basic middleware which logs the URI of the request being handled could be written as:\n\nMiddlewares can be added to a router using `Router.Use()`:\n\nA more complex authentication middleware, which maps session token to users, could be written as:\n\nNote: The handler chain will be stopped if your middleware doesn't call `next.ServeHTTP()` with the corresponding parameters. This can be used to abort a request if the middleware writer wants to.","homepage":"https://github.com/2lambda123/mux","licenses":"BSD-3-Clause","normalized_licenses":["BSD-3-Clause"],"repository_url":"https://github.com/2lambda123/mux","keywords_array":[],"namespace":"github.com/2lambda123","versions_count":14,"first_release_published_at":"2017-01-17T07:01:07.000Z","latest_release_published_at":"2023-10-18T11:23:00.000Z","latest_release_number":"v1.8.1","last_synced_at":"2026-03-28T07:02:03.113Z","created_at":"2023-12-13T01:36:13.733Z","updated_at":"2026-03-28T07:02:03.114Z","registry_url":"https://pkg.go.dev/github.com/2lambda123/mux","install_command":"go get github.com/2lambda123/mux","documentation_url":"https://pkg.go.dev/github.com/2lambda123/mux#section-documentation","metadata":{},"repo_metadata":{"uuid":"726748973","full_name":"2lambda123/mux","owner":"2lambda123","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-03T09:36:48.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-12-03T10:25:13.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2lambda123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-12-03T09:29:22.000Z","updated_at":"2023-12-03T10:25:16.276Z","dependencies_parsed_at":"2023-12-03T10:35:20.225Z","dependency_job_id":null,"html_url":"https://github.com/2lambda123/mux","commit_stats":null,"previous_names":["2lambda123/mux"],"tags_count":15,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lambda123%2Fmux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lambda123%2Fmux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lambda123%2Fmux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lambda123%2Fmux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2lambda123","download_url":"https://codeload.github.com/2lambda123/mux/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":176137119,"owners_count":10359296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"repo_metadata_updated_at":"2023-12-13T16:09:40.250Z","dependent_packages_count":0,"downloads":null,"downloads_period":null,"dependent_repos_count":0,"rankings":{"downloads":null,"dependent_repos_count":10.779397314443685,"dependent_packages_count":9.564379406084258,"stargazers_count":25.344157256077732,"forks_count":18.85539971418378,"docker_downloads_count":null,"average":16.135833422697363},"purl":"pkg:golang/github.com/2lambda123/mux","advisories":[],"docker_usage_url":"https://docker.ecosyste.ms/usage/go/github.com/2lambda123/mux","docker_dependents_count":null,"docker_downloads_count":null,"usage_url":"https://repos.ecosyste.ms/usage/go/github.com/2lambda123/mux","dependent_repositories_url":"https://repos.ecosyste.ms/api/v1/usage/go/github.com/2lambda123/mux/dependencies","status":null,"funding_links":[],"critical":null,"issue_metadata":null,"versions_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2F2lambda123%2Fmux/versions","version_numbers_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2F2lambda123%2Fmux/version_numbers","dependent_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2F2lambda123%2Fmux/dependent_packages","related_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2F2lambda123%2Fmux/related_packages","codemeta_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2F2lambda123%2Fmux/codemeta","maintainers":[]}