项目作者: gorilla

项目描述 :
A collection of useful middleware for Go HTTP services & web applications 🛃
高级语言: Go
项目地址: git://github.com/gorilla/handlers.git
创建时间: 2013-02-01T03:53:49Z
项目社区:https://github.com/gorilla/handlers

开源协议:BSD 2-Clause "Simplified" License

下载


gorilla/handlers

Testing
Codecov
GoDoc
Sourcegraph

Package handlers is a collection of handlers (aka “HTTP middleware”) for use
with Go’s net/http package (or any framework supporting http.Handler), including:

Other handlers are documented on the Gorilla
website
.

Example

A simple example using handlers.LoggingHandler and handlers.CompressHandler:

  1. import (
  2. "net/http"
  3. "github.com/gorilla/handlers"
  4. )
  5. func main() {
  6. r := http.NewServeMux()
  7. // Only log requests to our admin dashboard to stdout
  8. r.Handle("/admin", handlers.LoggingHandler(os.Stdout, http.HandlerFunc(ShowAdminDashboard)))
  9. r.HandleFunc("/", ShowIndex)
  10. // Wrap our server with our gzip handler to gzip compress all responses.
  11. http.ListenAndServe(":8000", handlers.CompressHandler(r))
  12. }

License

BSD licensed. See the included LICENSE file for details.