Documentation ¶
Index ¶
- func DefaultHeaders() []string
- func FromContext(ctx context.Context) string
- func Handler(h http.Handler, g Generator, headerNames ...string) http.Handler
- func LogHandler(h slog.Handler) slog.Handler
- func LogHandlerWithKey(h slog.Handler, key string) slog.Handler
- func Middleware(g Generator, headerNames ...string) func(http.Handler) http.Handler
- type Generator
- type GeneratorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultHeaders ¶
func DefaultHeaders() []string
DefaultHeaders returns the common header keys used to propagate the request ID.
func FromContext ¶
FromContext retrieves the request ID from the provided context. If not found, it returns an empty string.
func Handler ¶
Handler decorates the provided http.Handler with middleware that appends a request ID to the response header and the request context. If no header names are provided, it defaults to DefaultHeaders(). Otherwise, it uses the given header names. The first found header name in the request header is used to propagate the request ID. If none are found, it uses the first header name.
func LogHandler ¶
LogHandler decorates the provided slog.Handler with request ID logging, appending the request ID to the log record if it's available in the context. By default, it uses "request_id" as the record key. To customize the key, use LogHandlerWithKey.
func LogHandlerWithKey ¶
LogHandlerWithKey decorates the provided slog.Handler with request ID logging, using the specified key to append the request ID to the log record if available.