lambda

package module
v0.0.0-...-d96fe47 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 3 Imported by: 0

README

lambda

A framework to simplify lambda implementation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start[Req any, Resp any](handler Handler[Req, Resp], opts ...Option[Resp])

Start will start the lambda function with the given handler and httpOptions.

Start should be used when not using http events.

Types

type Context

type Context[Req any] struct {
	Context context.Context
	Request Req
	Locals  map[string]any
}

func (*Context[Req]) GetLocal

func (l *Context[Req]) GetLocal(key string) (any, bool)

func (*Context[Req]) SetLocal

func (l *Context[Req]) SetLocal(key string, value any) *Context[Req]

func (*Context[Req]) UnsetLocal

func (l *Context[Req]) UnsetLocal(key string) *Context[Req]

type Handler

type Handler[Req any, Resp any] func(*Context[Req]) (Resp, error)

func Use

func Use[Req any, Resp any](handler Handler[Req, Resp], middlewares ...Middleware[Req, Resp]) Handler[Req, Resp]

type Middleware

type Middleware[Req any, Resp any] func(ctx *Context[Req], next Handler[Req, Resp]) (Resp, error)

type None

type None struct{}

None is an empty struct used when we are not interested on the request or response body.

type Option

type Option[Resp any] func(*options[Resp])

func WithErrorHandler

func WithErrorHandler[Resp any](h func(error) (Resp, error)) Option[Resp]

WithErrorHandler is an option that allows you to pass a custom error handler to the lambda function.

func WithResources

func WithResources[Resp any](r ...Resource) Option[Resp]

WithResources is an option that allows you to pass resources to the lambda function.

type Resource

type Resource interface {
	Name() string
	Start(context.Context) error
}

Resource is an interface that represents a resource that can be started and stopped. Example: A connection to the database or message broker, etc;

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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