- Notifications
You must be signed in to change notification settings - Fork277
Package gorilla/handlers is a collection of useful middleware for Go HTTP services & web applications 🛃
License
NotificationsYou must be signed in to change notification settings
gorilla/handlers
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Package handlers is a collection of handlers (aka "HTTP middleware") for usewith Go'snet/http package (or any framework supportinghttp.Handler), including:
- LoggingHandler for logging HTTP requests in the ApacheCommon LogFormat.
- CombinedLoggingHandler for logging HTTP requests in the ApacheCombined LogFormat commonly used byboth Apache and nginx.
- CompressHandler for gzipping responses.
- ContentTypeHandler for validating requests against a list of acceptedcontent types.
- MethodHandler for matching HTTP methods against handlers in a
map[string]http.Handler - ProxyHeaders for populating
r.RemoteAddrandr.URL.Schemebased on theX-Forwarded-For,X-Real-IP,X-Forwarded-Protoand RFC7239Forwardedheaders when running a Go server behind a HTTP reverse proxy. - CanonicalHost for re-directing to the preferred host when handling multipledomains (i.e. multiple CNAME aliases).
- RecoveryHandler for recovering from unexpected panics.
Other handlers are documentedon the Gorillawebsite.
A simple example usinghandlers.LoggingHandler andhandlers.CompressHandler:
import ("net/http""github.com/gorilla/handlers")funcmain() {r:=http.NewServeMux()// Only log requests to our admin dashboard to stdoutr.Handle("/admin",handlers.LoggingHandler(os.Stdout,http.HandlerFunc(ShowAdminDashboard)))r.HandleFunc("/",ShowIndex)// Wrap our server with our gzip handler to gzip compress all responses.http.ListenAndServe(":8000",handlers.CompressHandler(r))}
BSD licensed. See the included LICENSE file for details.
About
Package gorilla/handlers is a collection of useful middleware for Go HTTP services & web applications 🛃
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.