middleware

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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 CtxWithID

func CtxWithID(ctx context.Context, id xid.ID) context.Context

CtxWithID adds the given xid.ID to the context

func CustomHeaderHandler

func CustomHeaderHandler(fieldKey, header string) func(next http.Handler) http.Handler

CustomHeaderHandler adds given header from request's header as a field to the context's logger using fieldKey as field key.

func IDFromCtx

func IDFromCtx(ctx context.Context) (id xid.ID, ok bool)

IDFromCtx returns the unique id associated to the context if any.

func IDFromRequest

func IDFromRequest(r *http.Request) (id xid.ID, ok bool)

IDFromRequest returns the unique id associated to the request if any.

func Logger

func Logger() gin.HandlerFunc

Logger injects log into requests context.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL