middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIGatewayV1

func CommonAPIGatewayV1

func CommonAPIGatewayV1(outputter metrics.Outputter) APIGatewayV1

CommonAPIGatewayV1 returns a slice of common middleware for handlers of events.APIGatewayProxyRequest that return events.APIGatewayProxyResponse

type NoResponse

type NoResponse[E any] interface {
	// Wrap returns a function that receives an event and returns an error. The next parameter is the next function to
	// be called in the chain of middleware and handlers, and should always be called unless the desired outcome is to
	// prevent the request from proceeding (i.e. a validation middleware could return an error straight away and
	// prevent an invalid request from being further processed)
	Wrap(next func(context.Context, E) error) func(context.Context, E) error
}

NoResponse [E any] interface should be implemented for middleware of handlers of event type E that do not return a response.

func Common

func Common[E any](outputter metrics.Outputter) []NoResponse[E]

Common [E any] returns a slice of common middleware for handlers of event type E that do not return a response.

func NewContext

func NewContext[E any]() NoResponse[E]

NewContext returns an implementation of NoResponse for the context middleware.

The context middleware adds additional information to the context of each request using the github.com/ellogroup/ello-golang-ctx/logctx package. This includes at the very least a request id.

func NewMetrics

func NewMetrics[E any](outputter metrics.Outputter) NoResponse[E]

NewMetrics returns an implementation of NoResponse for the metrics middleware.

The metrics middleware outputs the request start and end. The request start output contains the event and the request end output contains the duration of the request.

Outputters need to implement the `metrics.Outputter` interface from the github.com/ellogroup/ello-golang-metrics/metrics package.

type S3

func CommonS3

func CommonS3(outputter metrics.Outputter) S3

CommonS3 returns a slice of common middleware for handlers of events.S3Event

type SNS

type SNS []NoResponse[events.SNSEvent]

func CommonSNS

func CommonSNS(outputter metrics.Outputter) SNS

CommonSNS returns a slice of common middleware for handlers of events.SNSEvent

type SQS

type SQS []NoResponse[events.SQSEvent]

func CommonSQS

func CommonSQS(outputter metrics.Outputter) SQS

CommonSQS returns a slice of common middleware for handlers of events.SQSEvent

type WithResponse

type WithResponse[E, R any] interface {
	// Wrap returns a function that receives an event and returns a response/error. The next parameter is the next
	// function to be called in the chain of middleware and handlers, and should always be called unless the desired
	// outcome is to prevent the request from proceeding (i.e. a validation middleware could return an error straight
	// away and prevent an invalid request from being further processed)
	Wrap(next func(context.Context, E) (R, error)) func(context.Context, E) (R, error)
}

WithResponse [E, R any] interface should be implemented for middleware of handlers of event type E that return a response type R.

func CommonWithResponse

func CommonWithResponse[E, R any](outputter metrics.Outputter) []WithResponse[E, R]

CommonWithResponse [E, R any] returns a slice of common middleware for handlers of event type E that return a response type R.

func NewContextWithResponse

func NewContextWithResponse[E, R any]() WithResponse[E, R]

NewContextWithResponse returns an implementation of WithResponse for the context middleware.

The context middleware adds additional information to the context of each request using the github.com/ellogroup/ello-golang-ctx/logctx package. This includes at the very least a request id.

For API Gateway v1 requests the context also includes the method, domain and path of the request. The response is also updated to include the request id within the header `x-request-id`.

func NewMetricsWithResponse

func NewMetricsWithResponse[E, R any](outputter metrics.Outputter) WithResponse[E, R]

NewMetricsWithResponse returns an implementation of WithResponse for the metrics middleware.

The metrics middleware outputs the request start and end. The request start output contains the event and the request end output contains the duration of the request.

For API Gateway v1 requests the output also contains the status code of the response.

Outputters need to implement the `metrics.Outputter` interface from the github.com/ellogroup/ello-golang-metrics/metrics package.

Jump to

Keyboard shortcuts

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