router

package module
v0.0.0-...-4eb6788 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 7 Imported by: 0

README

Background

This module is intended to route AWS API Gateway proxy events for lambda functions.

Users are able to register handlers for each API resource along with an error handler and define mandatory query parameters.

If the client fails to pass required query parmeters the router will respond with the following:

{
    "StatusCode" : 400,
    "Body" : "endpoint requires the following query paramters: p1, p2"
}

If the client attempts to hit and resource which is not registered, the following will be returned:

{
    "StatusCode" : 404
}

Example Code


func Handler(_ context.Context, r events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
    // This is only an example! The router generally should be initialized once and reused!
	router := New()
	router.RegisterGet(
		"/path",
		handler.Builder().
			Handler(getFunction).
			ErrorHandler(errorFunction).
			MandatoryQueryParameters([]string{"param1"}).
			Build(),
	)
	event := events.APIGatewayProxyRequest{
		HTTPMethod: "GET",
		Resource:   "/path",
	}
	return router.Route(event), nil
}

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
}

func New

func New() *Router

func (*Router) RegisterGet

func (r *Router) RegisterGet(path string, handler handler.Handler) error

func (*Router) RegisterPatch

func (r *Router) RegisterPatch(path string, handler handler.Handler) error

func (*Router) RegisterPost

func (r *Router) RegisterPost(path string, handler handler.Handler) error

func (*Router) RegisterPut

func (r *Router) RegisterPut(path string, handler handler.Handler) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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