...

Source file src/github.com/go-chi/chi/middleware/middleware.go

Documentation: github.com/go-chi/chi/middleware

     1  package middleware
     2  
     3  import "net/http"
     4  
     5  // New will create a new middleware handler from a http.Handler.
     6  func New(h http.Handler) func(next http.Handler) http.Handler {
     7  	return func(next http.Handler) http.Handler {
     8  		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
     9  			h.ServeHTTP(w, r)
    10  		})
    11  	}
    12  }
    13  
    14  // contextKey is a value for use with context.WithValue. It's used as
    15  // a pointer so it fits in an interface{} without allocation. This technique
    16  // for defining context keys was copied from Go 1.7's new use of context in net/http.
    17  type contextKey struct {
    18  	name string
    19  }
    20  
    21  func (k *contextKey) String() string {
    22  	return "chi/middleware context value " + k.name
    23  }
    24  

View as plain text