lambdamux

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 7 Imported by: 0

README

aws-lambda-mux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartLocalServer

func StartLocalServer(addr string) error

Types

type APIGatewayProxy

type APIGatewayProxy struct {
	Handler ResourceHandler
}

APIGatewayProxy provides an Lambda Handler for proxied Lambda invokes from API Gateway.

func (APIGatewayProxy) Invoke

func (p APIGatewayProxy) Invoke(ctx context.Context, payload []byte) ([]byte, error)

Invoke invokes the API Gateway API call. Implements lambda's Handler interface.

Deserializes the request as an APIGatewayProxyRequest, and serializes the response as a APIGatewayProxyResponse.

type APIGatewayProxyRequest

type APIGatewayProxyRequest struct {
	events.APIGatewayProxyRequest
	HTTPHeader http.Header `json:"-"`
}

APIGatewayProxyRequest provides a proxy request wrapper for deserializing the events.APIGatewayProxyRequest with Go's http.Header formated headers. Simplifies the conversion between Go's http.Header and lambda's events multi value header parameter.

func (*APIGatewayProxyRequest) UnmarshalJSON

func (r *APIGatewayProxyRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals APIGatewayProxyRequest with the MultiValueHeaders deserialized as Go http.Header.

type APIGatewayProxyResponse

type APIGatewayProxyResponse struct {
	events.APIGatewayProxyResponse
	HTTPHeader http.Header `json:"-"`
}

APIGatewayProxyResponse serializes the events.APIGatewayResponse with Go's http.Header serialized as a MultiValueHeaders. Simplifies the conversion between Go's http.Header and lambda's events multi value header parameter.

func (APIGatewayProxyResponse) MarshalJSON

func (r APIGatewayProxyResponse) MarshalJSON() ([]byte, error)

MarshalJSON marshals the response as an JSON document.

type LocalServer

type LocalServer struct {
}

type ResourceHandler

type ResourceHandler interface {
	ServeResource(context.Context, APIGatewayProxyRequest) (APIGatewayProxyResponse, error)
}

ResourceHandler is the interface for APIGatewayProxy Lambda resource handlers for implementations to provide resource handlers.

func ResourceHandlerWithTimeout

func ResourceHandlerWithTimeout(dur time.Duration, handler ResourceHandler) ResourceHandler

ResourceHandlerWithTimeout provides a resource handler with a configured timeout that will be invoked per serve resource.

type ResourceHandlerFunc

type ResourceHandlerFunc func(context.Context, APIGatewayProxyRequest) (
	resp APIGatewayProxyResponse, err error,
)

ResourceHandlerFunc provides wrapping of a function as the ResourceHandler.

func (ResourceHandlerFunc) ServeResource

ServeResource implements the ResourceHandler interface and delegates to the function to handle the resource.

type ServeMethod

type ServeMethod struct {
	// contains filtered or unexported fields
}

ServeMethod is an API Gateway Proxy resource handler delegating resource requests to resource handlers filtered by HTTP request method.

func NewServeMethod

func NewServeMethod() *ServeMethod

NewServeMethod initializes and returns a ServeMethod that HTTP methods can be added to via the Handle method.

func (*ServeMethod) Handle

func (s *ServeMethod) Handle(method string, handler ResourceHandler) *ServeMethod

Handle adds a new ResourceHandler associated with a HTTP request method. Replaces existing methods that match.

HTTP request methods are not case sensitive.

func (*ServeMethod) ServeResource

func (s *ServeMethod) ServeResource(
	ctx context.Context, req APIGatewayProxyRequest,
) (resp APIGatewayProxyResponse, err error)

ServeResource implements the ResourceHandler interface, delegating resource requests to the ResourceHandler associated with the HTTP request method.

type ServeResource

type ServeResource struct {
	// contains filtered or unexported fields
}

ServeResource is an API Gateway Proxy Lambda resource handler that matches API Gateway request resources by exact name. Delegates to the resource handler by name.

Resource name must match exactly, including path parameters.

func NewServeResource

func NewServeResource() *ServeResource

NewServeResource initializes and returns a ServeResource that resource handlers can be added to via the Handle method.

func (*ServeResource) Handle

func (s *ServeResource) Handle(resource string, handler ResourceHandler) *ServeResource

Handle adds a new resource handler for the resource.

func (*ServeResource) ServeResource

func (s *ServeResource) ServeResource(
	ctx context.Context, req APIGatewayProxyRequest,
) (resp APIGatewayProxyResponse, err error)

ServeResource implements the ResourceHandler interface, and delegates the requests to the registered handler. If no handler is found returns an error.

Jump to

Keyboard shortcuts

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