lambdamux

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultHandlerPrefix = "Invoke"

Variables

View Source
var ErrNotFound = errors.New(`route not found`)

ErrNotFound is a well-known error that a route was not found. Using std errors.New here since we don't want a stack

Functions

func IgnoreCase

func IgnoreCase(name string) string

Types

type Handler

type Handler interface {
	Invoke(ctx context.Context, payload []byte) ([]byte, error)
}

Handler is identical to lambda.Handler.

func CacheProxy

func CacheProxy(maxAge time.Duration, handler Handler) Handler

func Chain

func Chain(handlers ...Handler) Handler

Chain tries handlers in sequence while a NotFound error is returned.

type HandlerFunc

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

HandlerFunc is a function implementing Handler

func (HandlerFunc) Invoke

func (f HandlerFunc) Invoke(ctx context.Context, payload []byte) ([]byte, error)

Invoke implements lambda.Handler

type Mux

type Mux struct {
	// If set, it will normalize route names.
	RouteName func(name string) string
	// Decorate can intercept new handlers and add decorations
	Decorate func(key string, handler Handler) Handler
	// JSON
	JSON jsoniter.API // defaults to jsoniter.ConfigCompatibleWithStandardLibrary
	// Validate sets a custom validation function to be injected into every route handler
	Validate func(payload interface{}) error
	// IgnoreDuplicates will not return errors when duplicate route handlers are added to the mux
	IgnoreDuplicates bool
	// contains filtered or unexported fields
}

Mux dispatches handling of a Lambda events

func (*Mux) Get

func (m *Mux) Get(name string) (Handler, error)

func (*Mux) Handle

func (m *Mux) Handle(name string, handler interface{}) error

Handle applies any decoration and adds a handler to the mux. It fails if the handler does not meet the signature requirements. It overrides previously defined routes without error if IgnoreDuplicates is set.

func (*Mux) HandleMethodsPrefix

func (m *Mux) HandleMethodsPrefix(prefix string, receivers ...interface{}) error

HandleMethodsPrefix add all routes from a struct to the Mux. It fails if a method does not meet the signature requirements. It overrides previously defined routes without error if IgnoreDuplicates is set

func (*Mux) Handlers

func (m *Mux) Handlers() (handlers []RouteHandler)

Handlers returns all handlers added to the mux.

func (*Mux) Invoke

func (m *Mux) Invoke(ctx context.Context, payload []byte) ([]byte, error)

func (*Mux) MustHandle

func (m *Mux) MustHandle(name string, handler interface{})

func (*Mux) MustHandleMethods

func (m *Mux) MustHandleMethods(receivers ...interface{})

MustHandleMethods add all routes from a struct to the Mux or panics. It overrides previously defined routes without error if IgnoreDuplicates is set

type RouteError

type RouteError interface {
	error
	Route() string
}

RouteError is the error implemented by errors returned from a route handler

type RouteHandler

type RouteHandler interface {
	Handler
	Route() string
}

Jump to

Keyboard shortcuts

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