mux

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 3 Imported by: 10 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoAuth

func NoAuth(_ events.Request) (events.Response, error)

NoAuth is an empty AuthFunc

func NoCheck

func NoCheck(_ events.Request) bool

NoCheck is an empty CheckFunc

func NoError

func NoError(_ events.Request, _ error) (events.Response, error)

NoError is an empty ErrorFunc

func Start

func Start(r Receiver)

Start launches a lambda handler from the Receiver

Types

type CheckFunc

type CheckFunc func(events.Request) bool

CheckFunc takes a events.Request and returns if the receiver can handle on it

type Dispatcher

type Dispatcher struct {
	Receivers []Receiver
	SimpleReceiver
}

Dispatcher is a meta-receiver which sends requests to other receivers

func NewDispatcher

func NewDispatcher(receivers ...Receiver) *Dispatcher

NewDispatcher is a helper to build a dispatcher from a list of receivers

func (*Dispatcher) Handle

func (d *Dispatcher) Handle(req events.Request) (events.Response, error)

Handle handles an incoming request by checking for a matching receiver

type ErrorFunc

type ErrorFunc func(events.Request, error) (events.Response, error)

ErrorFunc takes a events.Request and error and returns a crafted error events.Response

type HandleFunc

type HandleFunc func(events.Request) (events.Response, error)

HandleFunc takes a events.Request and returns a events.Response and error

type Receiver

type Receiver interface {
	Check(events.Request) bool
	Handle(events.Request) (events.Response, error)
	Auth(events.Request) (events.Response, error)
	Error(events.Request, error) (events.Response, error)
}

Receiver defines the format of an object that can process events.Requests

func NewReceiver

func NewReceiver(cf CheckFunc, af HandleFunc, hf HandleFunc, ef ErrorFunc) Receiver

NewReceiver generates a receiver from functions

type Route

type Route struct {
	Path *regexp.Regexp
	SimpleReceiver
}

Route is a receiver that works based on a regex path

func NewRoute

func NewRoute(path *regexp.Regexp, handler HandleFunc) *Route

NewRoute is a helper to convert a regexp and handlefunc into a Route Receiver

func NewRouteWithAuth added in v0.5.0

func NewRouteWithAuth(path *regexp.Regexp, handler HandleFunc, auth HandleFunc) *Route

NewRouteWithAuth is a helper to conver a regexp, handler, and auth func into a Route Receiver

func (*Route) Check

func (r *Route) Check(req events.Request) bool

Check tests if the path matches for the route

func (*Route) Handle

func (r *Route) Handle(req events.Request) (events.Response, error)

Handle runs the handle func with path regexp injected

type SimpleReceiver

type SimpleReceiver struct {
	CheckFunc  CheckFunc
	AuthFunc   HandleFunc
	HandleFunc HandleFunc
	ErrorFunc  ErrorFunc
}

SimpleReceiver defines a basic Receiver composed of 4 functions

func (*SimpleReceiver) Auth

func (rs *SimpleReceiver) Auth(req events.Request) (events.Response, error)

Auth determines if the events.Request is authorized to proceed

func (*SimpleReceiver) Check

func (rs *SimpleReceiver) Check(req events.Request) bool

Check determines if the receiver can handle the given events.Request

func (*SimpleReceiver) Error

func (rs *SimpleReceiver) Error(req events.Request, err error) (events.Response, error)

Error generates an error events.Response of the events.Request could not be handled

func (*SimpleReceiver) Handle

func (rs *SimpleReceiver) Handle(req events.Request) (events.Response, error)

Handle responds to the events.Request

Directories

Path Synopsis
receivers

Jump to

Keyboard shortcuts

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