middleware

package
v0.0.0-...-1db7b98 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDKey string = "requestid"

RequestIDKey is the fiber context key for the request ID.

Variables

View Source
var ErrMissingRequestID = errors.New("no request ID set on request context")

ErrMissingRequestID is returned when a request ID is not present in the context.

Functions

func CORS

func CORS(allowOrigins string) fiber.Handler

CORS returns a middleware that handles OPTIONS requests and sets the CORS headers on the response.

func RequestIDFrom

func RequestIDFrom(c *fiber.Ctx) (string, error)

RequestIDFrom returns the request ID from the Fiber context, or ErrMissingRequestID if no request ID is present.

func RequestIDInjection

func RequestIDInjection() fiber.Handler

RequestIDInjection returns middleware injects a UUID into the context of each request.

func RequestScopedLoggerInjection

func RequestScopedLoggerInjection(logger Logger) fiber.Handler

RequestScopedLoggerInjection is Fiber middleware that adds a request-scoped logger containing the current request ID to the Fiber context.

func RequestStatsLogging

func RequestStatsLogging(out io.Writer) fiber.Handler

RequestStatsLogging wraps the standard Fiber logger middleware, specifying a log format that can be reused consistently across the application (e.g. between the application server and test servers).

Types

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger represents the minimal set of methods required to log messages.

func LoggerFrom

func LoggerFrom(c *fiber.Ctx) Logger

LoggerFrom returns the request-scoped logger from the Fiber context, or [noOpLogger] if no logger is present.

type MockLogger

type MockLogger struct {
	Buf io.ReadWriter
}

func (*MockLogger) Printf

func (m *MockLogger) Printf(format string, v ...interface{})

Jump to

Keyboard shortcuts

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