Documentation ¶
Overview ¶
Package requestid provides functionalities to inject and extract request IDs from the context.
Index ¶
- Variables
- func ContextWithRequestID(ctx context.Context, id string) context.Context
- func FromContext(ctx context.Context) string
- func HandlerMiddleware() func(http.Handler) http.Handler
- func NewHandler(h http.Handler) http.Handler
- func NewRoundTripper(rt http.RoundTripper) http.RoundTripper
- func RoundTripperMiddleware() func(http.RoundTripper) http.RoundTripper
- type Propagator
Constants ¶
This section is empty.
Variables ¶
var DefaultTransport = NewRoundTripper(http.DefaultTransport)
DefaultTransport is a wrapper around http.DefaultTransport that injects the request ID into the header.
Functions ¶
func ContextWithRequestID ¶
ContextWithRequestID injects the request ID into the context.
func FromContext ¶
FromContext extracts the request ID from the context.
func HandlerMiddleware ¶
HandlerMiddleware returns a middleware that extracts the requestID from the header and injects it into the context.
func NewHandler ¶
NewHandler wraps a http.Handler to extract the requestID from the header and inject it into the context.
func NewRoundTripper ¶
func NewRoundTripper(rt http.RoundTripper) http.RoundTripper
NewRoundTripper wraps a http.RoundTripper to inject the request ID in the context into the header.
func RoundTripperMiddleware ¶
func RoundTripperMiddleware() func(http.RoundTripper) http.RoundTripper
RoundTripperMiddleware returns a middleware that injects the request ID in the context into the header.
Types ¶
type Propagator ¶
type Propagator struct{}
Propagator is a request ID propagator.
func (Propagator) Extract ¶
func (p Propagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
Extract extracts the request ID from the header.
func (Propagator) Fields ¶
func (p Propagator) Fields() []string
Fields returns the keys whose values are set with ContextWithRequestID.
func (Propagator) Inject ¶
func (p Propagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier)
Inject injects the request ID into the header.