lamway

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 9 Imported by: 0

README

Lamway

Is a manage layer implementation for AWS Lambda functions using API Gateway v1 or v2.

It provides a way to use go base http.Handler instances to manage all needed HTTP paths on the same lambda.

Requirements

  • Go >= 1.20

Installation

go get github.com/danteay/lamway

Example

Development Tasks

This project uses go-task to run common tasks. After installing go-task (or using the provided Nix flake), you can run:

  • task install # Download Go module dependencies
  • task pre-commit # Install pre-commit hooks
  • task vet # Run go vet checks
  • task lint # Run revive linter (depends on vet)
  • task format # Format code using gofmt
  • task test # Run unit tests with race and coverage
  • task cover # Open HTML coverage report (runs tests first)

If you use Nix, enter the dev shell with:

nix develop

Otherwise, install go-task from https://taskfile.dev.

Credits

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAPIGatewayRequest = errors.New("gateway: invalid APIGateway request struct configured")
)

Functions

This section is empty.

Types

type Decorator added in v0.1.0

type Decorator func(handler any) any

type Gateway

type Gateway[T any] struct {
	// contains filtered or unexported fields
}

Gateway wraps an http handler to enable use as a lambda.Handler

func New

func New[T any](opts ...Option) *Gateway[T]

New creates a gateway using the provided http.Handler enabling use in existing aws-lambda-go projects

func (*Gateway[T]) GetInvoker

func (gw *Gateway[T]) GetInvoker() any

GetInvoker returns the function that will be invoked by the lambda.Start call in the main function. This function will be decorated or not depending on the options passed to the New function.

func (*Gateway[T]) Start

func (gw *Gateway[T]) Start() (err error)

Start initializes the Lambda function by invoking the AWS Lambda runtime with the Gateway's invoker function. It ensures recovery from panics during execution and returns an error if a panic occurs or if initialization fails.

type HandlerProvider added in v0.1.0

type HandlerProvider func(ctx context.Context) http.Handler

type Logger added in v0.0.3

type Logger interface {
	Debugf(format string, args ...any)
}

type Option

type Option func(*options)

Option is a functional option for configuring the gateway.

func WithDecorator

func WithDecorator(d Decorator) Option

WithDecorator adds a Decorator function to the options for processing handlers.

func WithDefaultErrorHeaders

func WithDefaultErrorHeaders(headers map[string]string) Option

WithDefaultErrorHeaders sets a default error response header to be used in the options if the provided map is not empty.

func WithDefaultErrorResponse

func WithDefaultErrorResponse(res string) Option

WithDefaultErrorResponse sets a default error response string to be used in the options if the provided string is not empty.

func WithHTTPHandler

func WithHTTPHandler(h http.Handler) Option

WithHTTPHandler sets the provided http.Handler to the options' configuration.

func WithHandlerProvider added in v0.1.0

func WithHandlerProvider(p HandlerProvider) Option

WithHandlerProvider sets a custom HandlerProvider to lazily initialize the HTTP handler with context propagation.

func WithLogger added in v0.0.3

func WithLogger(l Logger) Option

WithLogger sets the provided Logger instance to the options' configuration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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