18 lines
410 B
Go
18 lines
410 B
Go
package middlewares
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
func InjectContextValuesBuilder(values map[ContextKey]any) func(http.Handler) http.Handler {
|
|
return func(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
for k, v := range values {
|
|
ctx = context.WithValue(ctx, k, v)
|
|
}
|
|
h.ServeHTTP(w, r.WithContext(ctx))
|
|
})
|
|
}
|
|
}
|