Documentation ¶
Overview ¶
Package lux contains types for creating an HTTP router for use in AWS lambda functions. The router supports RESTful HTTP methods & contains configuration for logging, request filtering & panic recovery.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
The HandlerFunc type defines what a handler function should look like.
type PanicInfo ¶
The PanicInfo type is passed to any custom registered panic handler functions and provides details on the request that caused the panic.
type RecoverFunc ¶
type RecoverFunc func(PanicInfo)
The RecoverFunc type defines what a panic recovery function should look like.
type Request ¶
type Request struct { events.APIGatewayProxyRequest Context context.Context `json:"-"` }
The Request type represents an incoming HTTP request.
type Response ¶
type Response events.APIGatewayProxyResponse
The Response type represents an outgoing HTTP response.
type ResponseWriter ¶
The ResponseWriter type allows for interacting with the HTTP response similarly to a triaditional HTTP handler in go.
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 ¶
Headers allows you to specify headers a request should have in order to use this route. You can use wildcards when you only care about a header's presence rather than its value.
func (*Route) Middleware ¶
func (r *Route) Middleware(fn ...HandlerFunc) *Route
Middleware allows you to apply middleware functions to a specific route, rather than globally to all routes.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
The Router type handles incoming requests & routes them to the registered handlers.
func (*Router) Handler ¶
func (r *Router) Handler(method string, fn HandlerFunc) *Route
Handler adds a given handler to the router.
func (*Router) Logging ¶
Logging sets the output for logs generated by the router. The logging package used is logrus (https://github.com/sirupsen/logrus). All logs written to os.Stdout and os.Stderr will automatically be picked up by CloudWatch. The logrus.Formatter interface allows you to specify a custom format for logs. By default, the output is JSON
func (*Router) Middleware ¶
func (r *Router) Middleware(fn ...HandlerFunc) *Router
Middleware adds a middleware function to the router. These methods will be called prior to the route handler and allow you to perform processing on the request before your handler is executed.
func (*Router) Recovery ¶
func (r *Router) Recovery(fn RecoverFunc) *Router
Recovery sets a custom recovery handler that allows you to process panics using your own handler. Not providing a recovery handler does not mean that your panics are not handled. When no custom handler is specified your panic will be logged to os.Stdout and execution can resume.
func (*Router) ServeHTTP ¶
ServeHTTP handles an incoming HTTP request from the AWS API Gateway. If the request matches a registered route then the specified handler will be executed after any registered middleware.
If a handler cannot be found matching the HTTP method, a 405 response will be returned to the client.
If you have specified query or header filters to your route, a request that matches the HTTP method but lacks the required parameters/headers will result in a 406 response.
A panic will result in a 500 response.