middleware

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestIDHeader is the name of the header used to transmit the request ID.
	RequestIDHeader = "X-Request-Id"

	// DefaultRequestIDLengthLimit is the default maximum length for the request ID header value.
	DefaultRequestIDLengthLimit = 128
)

Variables

This section is empty.

Functions

func ContextRequestID

func ContextRequestID(ctx context.Context) (reqID string)

ContextRequestID extracts the Request ID from the context.

func Cors

func Cors(origin string) web.Middleware

func Errors

func Errors(log logrus.FieldLogger) web.Middleware

Errors handles errors coming out of the call chain. This middleware leverages a technique of opaque errors that allows to customize errors with behaviors without coupling them to a specific type. In this way, it's easier to create new errors compatible with the behavior used here.

func Fields

func Fields(err error) (map[string]interface{}, bool)

Fields extracts fields to be logged together with the error. If the error does not implement the Fields behavior, it returns 'ok' to false and other parameters should be ignored.

func Panics

func Panics() web.Middleware

Panics recovers from panics and converts the panic to an error so it is handled in Errors.

func RequestID

func RequestID() web.Middleware

RequestID is a middleware that injects a request ID into the context of each request. Retrieve it using ctx.Value(ReqIDKey). If the incoming request has a RequestIDHeader header then that value is used else a random value is generated.

func Response

func Response(err error) (interface{}, int, bool)

Response returns a body and status code to use as a web response. If the error does not implement the Response behavior, it returns false as third parameter and other parameters should be ignored.

Types

This section is empty.

Jump to

Keyboard shortcuts

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