1234567891011121314151617 |
- package middleware
- import (
- "context"
- "net/http"
- )
- // WithValue set k/v in a context chain.
- func WithValue(k, v interface{}) func(next http.Handler) http.Handler {
- return func(next http.Handler) http.Handler {
- f := func(w http.ResponseWriter, r *http.Request) {
- r = r.WithContext(context.WithValue(r.Context(), k, v))
- next.ServeHTTP(w, r)
- }
- return http.HandlerFunc(f)
- }
- }
|