Documentation ¶
Index ¶
- func AccessHandler() gin.HandlerFunc
- func CtxWithID(ctx context.Context, id xid.ID) context.Context
- func CustomHeaderHandler(fieldKey, header string) func(next http.Handler) http.Handler
- func IDFromCtx(ctx context.Context) (id xid.ID, ok bool)
- func IDFromRequest(r *http.Request) (id xid.ID, ok bool)
- func Logger() gin.HandlerFunc
- func MethodHandler(fieldKey string) gin.HandlerFunc
- func RequestIDHandler(fieldKey, headerName string) gin.HandlerFunc
- func URLHandler(fieldKey string) gin.HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessHandler ¶
func AccessHandler() gin.HandlerFunc
AccessHandler returns a handler that call f after each request.
func CustomHeaderHandler ¶
CustomHeaderHandler adds given header from request's header as a field to the context's logger using fieldKey as field key.
func IDFromRequest ¶
IDFromRequest returns the unique id associated to the request if any.
func MethodHandler ¶
func MethodHandler(fieldKey string) gin.HandlerFunc
MethodHandler adds the request method as a field to the context's logger using fieldKey as field key.
func RequestIDHandler ¶
func RequestIDHandler(fieldKey, headerName string) gin.HandlerFunc
RequestIDHandler returns a handler setting a unique id to the request which can be gathered using IDFromRequest(req). This generated id is added as a field to the logger using the passed fieldKey as field name. The id is also added as a response header if the headerName is not empty.
The generated id is a URL safe base64 encoded mongo object-id-like unique id. Mongo unique id generation algorithm has been selected as a trade-off between size and ease of use: UUID is less space efficient and snowflake requires machine configuration.
func URLHandler ¶
func URLHandler(fieldKey string) gin.HandlerFunc
URLHandler adds the requested URL as a field to the context's logger using fieldKey as field key.
Types ¶
This section is empty.