You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.go 684B

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