superkit/kit/middleware/middleware.go

19 lines
349 B
Go
Raw Normal View History

2024-06-04 10:16:51 +02:00
package middleware
2024-06-06 10:04:51 +02:00
import (
"context"
"net/http"
)
2024-06-04 10:16:51 +02:00
type (
RequestKey struct{}
ResponseHeadersKey struct{}
)
2024-06-06 10:04:51 +02:00
func WithRequest(next http.Handler) http.Handler {
2024-06-06 10:04:51 +02:00
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), RequestKey{}, r)
2024-06-06 10:04:51 +02:00
next.ServeHTTP(w, r.WithContext(ctx))
})
}