Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Generator ¶
Generator defines the function which should extract or generate a Request ID. See `DefaultGenerator` and `New` package-level functions.
var DefaultGenerator Generator = func(ctx *context.Context) string { id := ctx.ResponseWriter().Header().Get(xRequestIDHeaderKey) if id != "" { return id } id = ctx.GetHeader(xRequestIDHeaderKey) if id == "" { uid, err := uuid.NewRandom() if err != nil { ctx.StopWithStatus(500) return "" } id = uid.String() } ctx.Header(xRequestIDHeaderKey, id) return id }
DefaultGenerator is the default `Generator` that is used when nil is passed on `New` package-level function. It extracts the ID from the "X-Request-ID" request header value or, if missing, it generates a new UUID(v4) and sets the header and context value.
See `Get` package-level function too.
func HashGenerator ¶
HashGenerator uses the request's hash to generate a fixed-length Request ID. Note that one or many requests may contain the same ID, so it's not unique.
Click to show internal directories.
Click to hide internal directories.