lambdarouter

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-2-Clause Imports: 8 Imported by: 0

README

lambdarouter

GoDoc Reference Build Status Test Coverage Maintainability Go Report Card

This package contains a router capable of routing many AWS Lambda API gateway requests to anything that implements the aws-lambda-go/lambda.Handler interface, all in one Lambda function. It plays especially well with go-kit's awslambda transport package. Get started by reading below and visiting the GoDoc reference.

Initializing a Router

r := lambdarouter.New("prefix/")

r.Get("hello/{name}", helloHandler)
r.Post("hello/server", helloHandler)
r.Delete("hello", lambda.NewHandler(func() (events.APIGatewayProxyResponse, error) {
        return events.APIGatewayProxyResponse{
                Body: "nothing to delete",
        }, nil
}))

lambda.StartHandler(r)

Check out the examples/ folder for more fleshed out examples in the proper context.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

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

Router holds the defined routes for use upon invocation.

func New

func New(prefix string) Router

New initializes an empty router. The prefix parameter may be of any length.

func (*Router) Delete

func (r *Router) Delete(path string, handler lambda.Handler)

Delete adds a new DELETE method route to the router. The path parameter is the route path you wish to define. The handler parameter is a lambda.Handler to invoke if an incoming path matches the route.

func (*Router) Get

func (r *Router) Get(path string, handler lambda.Handler)

Get adds a new GET method route to the router. The path parameter is the route path you wish to define. The handler parameter is a lambda.Handler to invoke if an incoming path matches the route.

func (*Router) Group

func (r *Router) Group(prefix string, fn func(r *Router))

Group allows you to define many routes with the same prefix. The prefix parameter will be applied to all routes defined in the function. The fn parameter is a function in which the grouped routes should be defined.

func (Router) Invoke

func (r Router) Invoke(ctx context.Context, payload []byte) ([]byte, error)

Invoke implements the lambda.Handler interface for the Router type.

func (*Router) Patch

func (r *Router) Patch(path string, handler lambda.Handler)

Patch adds a new PATCH method route to the router. The path parameter is the route path you wish to define. The handler parameter is a lambda.Handler to invoke if an incoming path matches the route.

func (*Router) Post

func (r *Router) Post(path string, handler lambda.Handler)

Post adds a new POST method route to the router. The path parameter is the route path you wish to define. The handler parameter is a lambda.Handler to invoke if an incoming path matches the route.

func (*Router) Put

func (r *Router) Put(path string, handler lambda.Handler)

Put adds a new PUT method route to the router. The path parameter is the route path you wish to define. The handler parameter is a lambda.Handler to invoke if an incoming path matches the route.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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