Categorygithub.com/beglaryh/aws-lambda-router
modulepackage
0.0.0-20241101003659-4eb678875506
Repository: https://github.com/beglaryh/aws-lambda-router.git
Documentation: pkg.go.dev

# 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
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author

# Structs

No description provided by the author