awslambda

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package awslambda provides an AWS Lambda transport layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorEncoder

func DefaultErrorEncoder(ctx context.Context, err error) ([]byte, error)

DefaultErrorEncoder defines the default behavior of encoding an error response, where it returns nil, and the error itself.

Types

type DecodeRequestFunc

type DecodeRequestFunc[REQ any] func(context.Context, []byte) (REQ, error)

DecodeRequestFunc extracts a user-domain request object from an AWS Lambda payload.

type EncodeResponseFunc

type EncodeResponseFunc[RES any] func(context.Context, RES) ([]byte, error)

EncodeResponseFunc encodes the passed response object into []byte, ready to be sent as AWS Lambda response.

type ErrorEncoder

type ErrorEncoder func(ctx context.Context, err error) ([]byte, error)

ErrorEncoder is responsible for encoding an error.

type Handler

type Handler[REQ any, RES any] struct {
	// contains filtered or unexported fields
}

Handler wraps an endpoint.

func NewHandler

func NewHandler[REQ any, RES any](
	e endpoint.Endpoint[REQ, RES],
	dec DecodeRequestFunc[REQ],
	enc EncodeResponseFunc[RES],
	options ...HandlerOption[REQ, RES],
) *Handler[REQ, RES]

NewHandler constructs a new handler, which implements the AWS lambda.Handler interface.

func (*Handler[REQ, RES]) Invoke

func (h *Handler[REQ, RES]) Invoke(
	ctx context.Context,
	payload []byte,
) (resp []byte, err error)

Invoke represents implementation of the AWS lambda.Handler interface.

type HandlerFinalizerFunc

type HandlerFinalizerFunc func(ctx context.Context, resp []byte, err error)

HandlerFinalizerFunc is executed at the end of Invoke. This can be used for logging purposes.

type HandlerOption

type HandlerOption[REQ any, RES any] func(*Handler[REQ, RES])

HandlerOption sets an optional parameter for handlers.

func HandlerAfter

func HandlerAfter[REQ any, RES any](after ...HandlerResponseFunc[RES]) HandlerOption[REQ, RES]

HandlerAfter functions are only executed after invoking the endpoint but prior to returning a response.

func HandlerBefore

func HandlerBefore[REQ any, RES any](before ...HandlerRequestFunc) HandlerOption[REQ, RES]

HandlerBefore functions are executed on the payload byte, before the request is decoded.

func HandlerErrorEncoder

func HandlerErrorEncoder[REQ any, RES any](ee ErrorEncoder) HandlerOption[REQ, RES]

HandlerErrorEncoder is used to encode errors.

func HandlerErrorHandler

func HandlerErrorHandler[REQ any, RES any](errorHandler transport.ErrorHandler) HandlerOption[REQ, RES]

HandlerErrorHandler is used to handle non-terminal errors. By default, non-terminal errors are ignored.

func HandlerErrorLogger

func HandlerErrorLogger[REQ any, RES any](logger log.Logger) HandlerOption[REQ, RES]

HandlerErrorLogger is used to log non-terminal errors. By default, no errors are logged. Deprecated: Use HandlerErrorHandler instead.

func HandlerFinalizer

func HandlerFinalizer[REQ any, RES any](f ...HandlerFinalizerFunc) HandlerOption[REQ, RES]

HandlerFinalizer sets finalizer which are called at the end of request. By default no finalizer is registered.

type HandlerRequestFunc

type HandlerRequestFunc func(ctx context.Context, payload []byte) context.Context

HandlerRequestFunc may take information from the received payload and use it to place items in the request scoped context. HandlerRequestFuncs are executed prior to invoking the endpoint and decoding of the payload.

type HandlerResponseFunc

type HandlerResponseFunc[RES any] func(ctx context.Context, response RES) context.Context

HandlerResponseFunc may take information from a request context and use it to manipulate the response before it's marshaled. HandlerResponseFunc are executed after invoking the endpoint but prior to returning a response.

Jump to

Keyboard shortcuts

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