Ecosyste.ms: Repos
An open API service providing repository metadata for many open source software ecosystems.
Package Usage: go: github.com/gorilla/mux
Package mux implements a request router and dispatcher.
The name mux stands for "HTTP request multiplexer". Like the standard
http.ServeMux, mux.Router matches incoming requests against a list of
registered routes and calls a handler for the route that matches the URL
or other conditions. The main features are:
Let's start registering a couple of URL paths and handlers:
Here we register three routes mapping URL paths to handlers. This is
equivalent to how http.HandleFunc() works: if an incoming request URL matches
one of the paths, the corresponding handler is called passing
(http.ResponseWriter, *http.Request) as parameters.
Paths can have variables. They are defined using the format {name} or
{name:pattern}. If a regular expression pattern is not defined, the matched
variable will be anything until the next slash. For example:
Groups can be used inside patterns, as long as they are non-capturing (?:re). For example:
The names are used to create a map of route variables which can be retrieved
calling mux.Vars():
Note that if any capturing groups are present, mux will panic() during parsing. To prevent
this, convert any capturing groups to non-capturing, e.g. change "/{sort:(asc|desc)}" to
"/{sort:(?:asc|desc)}". This is a change from prior versions which behaved unpredictably
when capturing groups were present.
And this is all you need to know about the basic usage. More advanced options
are explained below.
Routes can also be restricted to a domain or subdomain. Just define a host
pattern to be matched. They can also have variables:
There are several other matchers that can be added. To match path prefixes:
...or HTTP methods:
...or URL schemes:
...or header values:
...or query values:
...or to use a custom matcher function:
...and finally, it is possible to combine several matchers in a single route:
Setting the same matching conditions again and again can be boring, so we have
a way to group several routes that share the same requirements.
We call it "subrouting".
For example, let's say we have several URLs that should only match when the
host is "www.example.com". Create a route for that host and get a "subrouter"
from it:
Then register routes in the subrouter:
The three URL paths we registered above will only be tested if the domain is
"www.example.com", because the subrouter is tested first. This is not
only convenient, but also optimizes request matching. You can create
subrouters combining any attribute matchers accepted by a route.
Subrouters can be used to create domain or path "namespaces": you define
subrouters in a central place and then parts of the app can register its
paths relatively to a given subrouter.
There's one more thing about subroutes. When a subrouter has a path prefix,
the inner routes use it as base for their paths:
Note that the path provided to PathPrefix() represents a "wildcard": calling
PathPrefix("/static/").Handler(...) means that the handler will be passed any
request that matches "/static/*". This makes it easy to serve static files with mux:
Now let's see how to build registered URLs.
Routes can be named. All routes that define a name can have their URLs built,
or "reversed". We define a name calling Name() on a route. For example:
To build a URL, get the route and call the URL() method, passing a sequence of
key/value pairs for the route variables. For the previous route, we would do:
...and the result will be a url.URL with the following path:
This also works for host and query value variables:
All variables defined in the route are required, and their values must
conform to the corresponding patterns. These requirements guarantee that a
generated URL will always match a registered route -- the only exception is
for explicitly defined "build-only" routes which never match.
Regex support also exists for matching Headers within a route. For example, we could do:
...and the route will match both requests with a Content-Type of `application/json` as well as
`application/text`
There's also a way to build only the URL host or path for a route:
use the methods URLHost() or URLPath() instead. For the previous route,
we would do:
And if you use subrouters, host and path defined separately can be built
as well:
Mux 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.
Typically, 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).
A very basic middleware which logs the URI of the request being handled could be written as:
Middlewares can be added to a router using `Router.Use()`:
A more complex authentication middleware, which maps session token to users, could be written as:
Note: 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.
14 versions
Latest release: 5 months ago
27,498 dependent packages
View more package details: https://packages.ecosyste.ms/registries/proxy.golang.org/packages/github.com/gorilla/mux
View more repository details: https://repos.ecosyste.ms/hosts/GitHub/repositories/gorilla%2Fmux
Dependent Repos 97,463
admariner/jitsu Fork of jitsucom/jitsu
Jitsu is an open-source data integration platform- v1.7.2 configurator/backend/go.sum
- v1.8.0 configurator/backend/go.sum
- v1.7.2 server/go.sum
Size: 29.4 MB - Last synced: 7 days ago - Pushed: 9 months ago
kmodules/resource-metadata
API for defining metadata about Kubernetes resources- v1.8.0 go.sum
Size: 75.1 MB - Last synced: 6 days ago - Pushed: 6 days ago
brotherlogic/logging
Logging for system- v1.6.2 go.sum
- v1.7.3 go.sum
Size: 597 KB - Last synced: 11 days ago - Pushed: 11 days ago
ossf/scorecard-action
Official GitHub Action for OpenSSF Scorecard.- v1.6.2 go.sum
- v1.7.2 go.sum
- v1.7.3 go.sum
- v1.8.0 go.sum
Size: 6.5 MB - Last synced: 3 days ago - Pushed: 3 days ago
kamden-rasmussen/PickupandGO
- v1.8.0 go.mod
- v1.8.0 go.sum
Size: 370 KB - Last synced: 9 months ago - Pushed: 12 months ago
nautible/nautible-app-ms-payment
nautible-app-payment project- v1.8.0 go.mod
- v1.8.0 go.sum
Size: 428 KB - Last synced: about 1 year ago - Pushed: over 1 year ago
zeromike/syft Fork of anchore/syft
CLI tool and library for generating a Software Bill of Materials from container images and filesystems- v1.6.2 go.sum
- v1.7.2 go.sum
- v1.7.3 go.sum
- v1.8.0 go.sum
Size: 10.4 MB - Last synced: 10 months ago - Pushed: almost 2 years ago
aberja/argo Fork of argoproj/argo-workflows
Argo Workflows: Get stuff done with Kubernetes.- v1.7.3 go.sum
- v1.8.0 go.sum
Size: 67.2 MB - Last synced: about 1 year ago - Pushed: about 1 year ago
krasish/test-infra Fork of kyma-project/test-infra
Test infrastructure for the Kyma project.- v1.6.2 development/gcp/cloud-functions/getfailureinstancedetails/go.sum
- v1.7.2 development/gcp/cloud-functions/getfailureinstancedetails/go.sum
- v1.7.3 development/gcp/cloud-functions/getfailureinstancedetails/go.sum
- v1.7.4 development/gcp/cloud-functions/getfailureinstancedetails/go.sum
- v1.8.0 development/gcp/cloud-functions/getfailureinstancedetails/go.sum
- v1.6.2 development/kyma-ci-force-bot/ciforcebot/go.sum
- v1.7.2 development/kyma-ci-force-bot/ciforcebot/go.sum
- v1.7.3 development/kyma-ci-force-bot/ciforcebot/go.sum
- v1.7.4 development/kyma-ci-force-bot/ciforcebot/go.sum
- v1.8.0 development/kyma-ci-force-bot/ciforcebot/go.sum
- v1.6.2 go.sum
- v1.7.2 go.sum
- v1.7.3 go.sum
- v1.7.4 go.sum
- v1.8.0 go.sum
Size: 15.3 MB - Last synced: about 1 year ago - Pushed: about 1 year ago
bytebuilders/installer
- v1.8.0 go.sum
Size: 17.7 MB - Last synced: about 10 hours ago - Pushed: about 17 hours ago
spolti/kie-cloud-operator Fork of kiegroup/kie-cloud-operator
OCP Operator for KIE- v1.6.2 go.sum
- v1.7.1 go.sum
- v1.7.2 go.sum
- v1.8.0 go.sum
Size: 100 MB - Last synced: 7 months ago - Pushed: 7 months ago
dhis2-sre/im-inspector
- v1.8.0 go.sum
Size: 334 KB - Last synced: about 1 month ago - Pushed: about 1 month ago
mchirico/montcoio
- v1.7.4 k8s/goCorsSSL_PV/go.mod
- v1.7.4 k8s/goCorsSSL_PV/go.sum
Size: 154 KB - Last synced: about 1 year ago - Pushed: over 1 year ago
murilo-bracero/raspstore
- v1.8.0 application/auth-service/go.mod
- v1.8.0 application/auth-service/go.sum
- v1.8.0 application/file-info-service/go.mod
- v1.8.0 application/file-info-service/go.sum
- v1.8.0 application/users-service/go.mod
- v1.8.0 application/users-service/go.sum
Size: 25.7 MB - Last synced: 5 months ago - Pushed: 5 months ago
cheqd/tendermint Fork of tendermint/tendermint
⟁ Tendermint Core (BFT Consensus) in Go- v1.6.2 go.sum
- v1.7.3 go.sum
Size: 142 MB - Last synced: about 2 months ago - Pushed: about 1 year ago
ryanlycch/go-zero-looklook Fork of Mikaelemmmm/go-zero-looklook
🔥基于go-zero(go zero) 微服务全技术栈开发最佳实践项目。Develop best practice projects based on the full technology stack of go zero (go zero) microservices.- v1.8.0 go.sum
Size: 101 MB - Last synced: about 2 months ago - Pushed: about 2 months ago
ahmedabu98/beam Fork of apache/beam
Apache Beam is a unified programming model for Batch and Streaming- v1.6.2 playground/backend/go.sum
- v1.7.3 playground/backend/go.sum
- v1.7.2 sdks/go.sum
Size: 364 MB - Last synced: 7 days ago - Pushed: 7 days ago
champ-oss/terraform-aws-metabase
- v1.7.2 test/src/go.sum
- v1.7.3 test/src/go.sum
Size: 218 KB - Last synced: 2 days ago - Pushed: 3 days ago
fahedouch/crossplane-runtime Fork of crossplane/crossplane-runtime
A set of libraries for writing Crossplane controllers.- v1.8.0 go.sum
Size: 2.37 MB - Last synced: 9 months ago - Pushed: 9 months ago
alexander-lipnitskiy/hlf-deploy
Deploy Hyperledger Fabric Network in Docker Swarm- v1.7.3 go.sum
Size: 1020 KB - Last synced: about 1 year ago - Pushed: about 1 year ago
dragan-novakovic/accord
Auth service- v1.8.0 api-gateway/go.mod
- v1.8.0 api-gateway/go.sum
Size: 10.3 MB - Last synced: 29 days ago - Pushed: 29 days ago
xav-b/crypto-stuff
Tinkering around- v1.8.0 streaming-ethereum-on-chain-data-to-questdb/go.sum
Size: 7.6 MB - Last synced: about 1 year ago - Pushed: about 1 year ago
denisandreenko/fire
FIRE is a p2p portfolio tracker which collects data from statements of supported p2p platforms and shows analytics of the entire portfolio- v1.8.0 go.mod
- v1.8.0 go.sum
Size: 3.51 MB - Last synced: 2 months ago - Pushed: 4 months ago
observIQ/grafana-agent Fork of grafana/agent
Telemetry agent for the LGTM stack.- v1.8.0 go.mod
- v1.6.2 go.sum
- v1.7.0 go.sum
- v1.7.1 go.sum
- v1.7.2 go.sum
- v1.7.3 go.sum
- v1.8.0 go.sum
Size: 48.3 MB - Last synced: 4 months ago - Pushed: 4 months ago
nostprumprajee/Traveler
- 53c1911da2b537f792e7cafcb446b05ffe33b996 demo-api-with-golang/src/Gopkg.lock
- 1.6.0 demo-api-with-golang/src/Gopkg.toml
- v1.6.2 go-contacts/go.mod
- v1.6.2 go-contacts/go.sum
- v1.6.2 gokit-examples/go.mod
- v1.6.2 gokit-examples/go.sum
Size: 77.6 MB - Last synced: about 1 year ago - Pushed: about 1 year ago
tharun208/loki Fork of grafana/loki
Like Prometheus, but for logs.- v1.8.0 go.mod
- v1.6.2 go.sum
- v1.7.1 go.sum
- v1.7.3 go.sum
- v1.8.0 go.sum
- v1.8.0 operator/go.mod
- v1.6.2 operator/go.sum
- v1.7.2 operator/go.sum
- v1.7.3 operator/go.sum
- v1.8.0 operator/go.sum
- v1.8.0 tools/lambda-promtail/go.mod
- v1.6.2 tools/lambda-promtail/go.sum
- v1.7.2 tools/lambda-promtail/go.sum
- v1.7.3 tools/lambda-promtail/go.sum
- v1.8.0 tools/lambda-promtail/go.sum
Size: 168 MB - Last synced: about 1 year ago - Pushed: about 1 year ago
tranminhduc4796/far_cry_online
The last project of Intek- v1.6.2 server/go.sum
Size: 16.1 MB - Last synced: about 1 year ago - Pushed: over 1 year ago
Tatsinnit/kubelogin Fork of Azure/kubelogin
A Kubernetes credential (exec) plugin implementing azure authentication- v1.8.0 go.sum
Size: 1.63 MB - Last synced: 2 months ago - Pushed: 2 months ago
Team-Kujira/ibc-go Fork of cosmos/ibc-go
Interblockchain Communication Protocol (IBC) implementation in Golang.- v1.8.0 e2e/go.mod
- v1.6.2 e2e/go.sum
- v1.7.3 e2e/go.sum
- v1.8.0 e2e/go.sum
- v1.8.0 go.mod
Size: 30.2 MB - Last synced: 5 months ago - Pushed: 6 months ago