package main import ( "context" "net/http" "time" ) type MsReq struct{} func CreateTimeoutCtx(msReq time.Duration) func(http.Handler) http.Handler { return func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { reqCtx := r.Context() reqCtx = context.WithValue(reqCtx, MsReq{}, msReq) r.WithContext(reqCtx) h.ServeHTTP(w, r) }) } } func main() { }