github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/gorilla/handlers/README.md (about)

     1  gorilla/handlers
     2  ================
     3  [![GoDoc](https://godoc.org/github.com/gorilla/handlers?status.svg)](https://godoc.org/github.com/gorilla/handlers) [![Build Status](https://travis-ci.org/gorilla/handlers.svg?branch=master)](https://travis-ci.org/gorilla/handlers)
     4  [![Sourcegraph](https://sourcegraph.com/github.com/gorilla/handlers/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/handlers?badge)
     5  
     6  
     7  Package handlers is a collection of handlers (aka "HTTP middleware") for use
     8  with Go's `net/http` package (or any framework supporting `http.Handler`), including:
     9  
    10  * [**LoggingHandler**](https://godoc.org/github.com/gorilla/handlers#LoggingHandler) for logging HTTP requests in the Apache [Common Log
    11    Format](http://httpd.apache.org/docs/2.2/logs.html#common).
    12  * [**CombinedLoggingHandler**](https://godoc.org/github.com/gorilla/handlers#CombinedLoggingHandler) for logging HTTP requests in the Apache [Combined Log
    13    Format](http://httpd.apache.org/docs/2.2/logs.html#combined) commonly used by
    14    both Apache and nginx.
    15  * [**CompressHandler**](https://godoc.org/github.com/gorilla/handlers#CompressHandler) for gzipping responses.
    16  * [**ContentTypeHandler**](https://godoc.org/github.com/gorilla/handlers#ContentTypeHandler) for validating requests against a list of accepted
    17    content types.
    18  * [**MethodHandler**](https://godoc.org/github.com/gorilla/handlers#MethodHandler) for matching HTTP methods against handlers in a
    19    `map[string]http.Handler`
    20  * [**ProxyHeaders**](https://godoc.org/github.com/gorilla/handlers#ProxyHeaders) for populating `r.RemoteAddr` and `r.URL.Scheme` based on the
    21    `X-Forwarded-For`, `X-Real-IP`, `X-Forwarded-Proto` and RFC7239 `Forwarded`
    22    headers when running a Go server behind a HTTP reverse proxy.
    23  * [**CanonicalHost**](https://godoc.org/github.com/gorilla/handlers#CanonicalHost) for re-directing to the preferred host when handling multiple 
    24    domains (i.e. multiple CNAME aliases).
    25  * [**RecoveryHandler**](https://godoc.org/github.com/gorilla/handlers#RecoveryHandler) for recovering from unexpected panics.
    26  
    27  Other handlers are documented [on the Gorilla
    28  website](http://www.gorillatoolkit.org/pkg/handlers).
    29  
    30  ## Example
    31  
    32  A simple example using `handlers.LoggingHandler` and `handlers.CompressHandler`:
    33  
    34  ```go
    35  import (
    36      "github.com/hellobchain/newcryptosm/http"
    37      "github.com/hellobchain/third_party/gorilla/handlers"
    38  )
    39  
    40  func main() {
    41      r := http.NewServeMux()
    42  
    43      // Only log requests to our admin dashboard to stdout
    44      r.Handle("/admin", handlers.LoggingHandler(os.Stdout, http.HandlerFunc(ShowAdminDashboard)))
    45      r.HandleFunc("/", ShowIndex)
    46  
    47      // Wrap our server with our gzip handler to gzip compress all responses.
    48      http.ListenAndServe(":8000", handlers.CompressHandler(r))
    49  }
    50  ```
    51  
    52  ## License
    53  
    54  BSD licensed. See the included LICENSE file for details.
    55