Documentation
¶
Overview ¶
Package middleware builds handler middlewares: logic that runs before and after each invocation of a Lambda handler, the Go side of Powertools' middleware factory.
A handler is any function aws-lambda-go's lambda.Start accepts in the (context, event) -> (result, error) shape; a middleware takes a handler and returns one that wraps it. Every handler-level Powertools utility (the logger's context injection, the tracer's handler capture, metrics flushing, idempotency) is such a middleware, so they stack with each other and with your own:
lambda.Start(middleware.Chain(handle,
middleware.New("audit", audit),
logResponse,
))
A middleware that does not care about the event type is a generic function, such as logResponse above, and Chain instantiates it for the handler at hand.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Func ¶
Func is the body of a middleware made with New: it receives the event and the next handler, and decides whether, when and how to call it.
type Middleware ¶
Middleware wraps a Handler in another one.
func After ¶
func After[E, R any](fn func(ctx context.Context, event E, result R, err error) (R, error)) Middleware[E, R]
After makes a middleware that runs fn after the handler, with what the handler returned; fn returns what the invocation returns.
type Option ¶
type Option func(*config)
Option configures a middleware made with New.
func WithTracerProvider ¶
func WithTracerProvider(tp trace.TracerProvider) Option
WithTracerProvider sends the spans of WithTracing to tp instead of the global tracer provider.
func WithTracing ¶
WithTracing records every run of the middleware as a span named "## <name>", so that its overhead shows in the trace. It defaults to the POWERTOOLS_TRACE_MIDDLEWARES environment variable. The spans go to the global OpenTelemetry tracer provider, which the tracing package sets up.