superkit/kit/middleware/middleware.go
2024-07-01 11:18:03 +02:00

18 lines
349 B
Go

package middleware
import (
"context"
"net/http"
)
type (
RequestKey struct{}
ResponseHeadersKey struct{}
)
func WithRequest(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), RequestKey{}, r)
next.ServeHTTP(w, r.WithContext(ctx))
})
}