Documentation ¶
Index ¶
- func GetRequestIDFromContext(ctx context.Context) (string, bool)
- func GetRequestIDFromRequest(r *http.Request) (string, bool)
- func New(genFn IDGenerator) func(http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func ULIDGenerator() string
- func UUIDGenerator() string
- type IDGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRequestIDFromContext ¶
GetRequestIDFromContext extracts the request ID from the provided context.
Parameters: - ctx: The context from which to extract the request ID.
Returns: - string: The extracted request ID. - bool: A boolean value indicating whether the request ID was successfully extracted.
func GetRequestIDFromRequest ¶
GetRequestIDFromRequest extracts the request ID from the provided HTTP request's context.
Parameters: - r: A pointer to the HTTP request from which to extract the request ID.
Returns: - string: The extracted request ID. - bool: A boolean value indicating whether the request ID was successfully extracted.
func New ¶
func New(genFn IDGenerator) func(http.Handler) http.Handler
New is a higher-order function that takes an IDGenerator function as an argument and returns a function that takes an http.Handler as an argument and returns an http.Handler.
Parameters: - genFn: A function that generates a unique ID.
Returns: - func(http.Handler) http.Handler: A function that wraps the provided http.Handler with request ID generation and setting.
func RequestID ¶
RequestID is a middleware function that wraps the provided http.Handler with request ID generation and setting. It also adds a "X-Request-Id" header to the response.
Parameters: - next: The http.Handler to be wrapped with request ID generation and setting.
Returns: - http.Handler: The wrapped http.Handler.
func ULIDGenerator ¶
func ULIDGenerator() string
ULIDGenerator is a function that generates a new ULID as a string.
func UUIDGenerator ¶
func UUIDGenerator() string
UUIDGenerator is a function that generates a new UUID as a string.
Types ¶
type IDGenerator ¶
type IDGenerator func() string
IDGenerator is a type definition for a function that generates a unique ID as a string.