FillContext returns a middleware that fills global context into a call context.
(fillers ...fillcontext.Filler)
| 22 | |
| 23 | // FillContext returns a middleware that fills global context into a call context. |
| 24 | func FillContext(fillers ...fillcontext.Filler) MiddlewareFunc { |
| 25 | return func(next http.Handler) http.Handler { |
| 26 | if len(fillers) == 0 { |
| 27 | return next |
| 28 | } |
| 29 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 30 | ctx := r.Context() |
| 31 | for _, fill := range fillers { |
| 32 | ctx = fill(ctx) |
| 33 | } |
| 34 | next.ServeHTTP(w, r.WithContext(ctx)) |
| 35 | }) |
| 36 | } |
| 37 | } |