lux

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

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

Go to latest
Published: Mar 1, 2018 License: MIT Imports: 7 Imported by: ? modules, 0 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.

README

lux

CircleCI GoDoc Go Report Card GitHub license FOSSA Status

An HTTP router for Golang lambda functions

usage

func main() {
  // Create a router
  router := lux.NewRouter()

  // Create a custom panic recovery function (optional). This allows you to do things
  // in the event one of your handlers panics.
  router.Recovery(recoverFunc)

  // Configure the logging (optional), anything in stdout or stderr should be
  // logged by AWS.
  router.Logging(os.Stdout, &logrus.JSONFormatter{})

  // Configure your routes for different HTTP methods. You can specify headers that
  // the request must contain to use this route.
  router.Handler("GET", getFunc).Headers("Content-Type", "application/json")
  router.Handler("PUT", putFunc).Headers("Content-Type", "application/json")
  router.Handler("POST", postFunc).Headers("Content-Type", "application/json")
  router.Handler("DELETE", deleteFunc).Headers("Content-Type", "application/json")

  // Start the lambda.
  lambda.Start(router.HandleRequest)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerFunc

The HandlerFunc type defines what a handler function should look like.

type RecoverFunc

type RecoverFunc func(events.APIGatewayProxyRequest, error)

The RecoverFunc type defines what a panic recovery function should look like.

type Route

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

The Route type defines a route that can be used by the router.

func (*Route) Headers

func (r *Route) Headers(pairs ...string) *Route

Headers allows you to specify headers a request should have in order to use this route.

type Router

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

The Router type handles incoming requests & routes them to the registered handlers.

func NewRouter

func NewRouter() *Router

NewRouter creates a new lambda router.

func (*Router) HandleRequest

HandleRequest determines which route an incoming HTTP request should be sent down. If no route has been specified for a given HTTP method, an error is returned.

func (*Router) Handler

func (r *Router) Handler(method string, fn HandlerFunc) *Route

Handler adds a given handler to the router.

func (*Router) Logging

func (r *Router) Logging(out io.Writer, format logrus.Formatter) *Router

Logging sets the output for logs generated by the router.

func (*Router) Recovery

func (r *Router) Recovery(fn RecoverFunc) *Router

Recovery sets a custom recovery handler that will be used when any handlers panic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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