internal

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertAPIGatewayProxyRequest

func ConvertAPIGatewayProxyRequest(ctx context.Context, e events.APIGatewayProxyRequest) (*http.Request, error)

ConvertAPIGatewayProxyRequest converts APIGatewayProxyRequest (v1) to *http.Request

func ConvertAPIGatewayV2HTTPRequest

func ConvertAPIGatewayV2HTTPRequest(ctx context.Context, e events.APIGatewayV2HTTPRequest) (*http.Request, error)

ConvertAPIGatewayV2HTTPRequest converts APIGatewayV2HTTPRequest (v2) to *http.Request

func ConvertResponseV1

func ConvertResponseV1(data ResponseData) (events.APIGatewayProxyResponse, error)

ConvertResponseV1 converts ResponseData to APIGatewayProxyResponse (v1)

func ConvertResponseV2

func ConvertResponseV2(data ResponseData) (events.APIGatewayV2HTTPResponse, error)

ConvertResponseV2 converts ResponseData to APIGatewayV2HTTPResponse (v2)

func ListenAndServe

func ListenAndServe[T any, R any](addr string, handler http.Handler, requestConverter RequestConverter[T], responseConverter ResponseConverter[R]) error

ListenAndServe is a generic function that sets up the Gateway and starts the Lambda handler

func NewContext

func NewContext[T any](ctx context.Context, e T) context.Context

NewContext returns a new Context with the API Gateway proxy RequestContext.

func RequestContext

func RequestContext[T any](ctx context.Context) (T, bool)

RequestContext retrieves the RequestContext from the context.

Types

type Gateway

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

Gateway is a generic struct that wraps an http.Handler and converter functions

func NewGateway

func NewGateway[T any, R any](handler http.Handler, requestConverter RequestConverter[T], responseConverter ResponseConverter[R]) *Gateway[T, R]

NewGateway creates a new Gateway with the given handler and converters

func (*Gateway[T, R]) Invoke

func (gw *Gateway[T, R]) Invoke(ctx context.Context, payload []byte) ([]byte, error)

Invoke handles the Lambda invocation by converting the event to an HTTP request, processing it, and converting the response back to the Lambda response format.

type Key

type Key int

Key is the type used for any items added to the request context.

func GetRequestContextKey

func GetRequestContextKey() Key

GetRequestContextKey returns the key used for storing the RequestContext in the context.

type RequestConverter

type RequestConverter[T any] func(context.Context, T) (*http.Request, error)

RequestConverter is a function type that converts an event of type T to an *http.Request

type ResponseConverter

type ResponseConverter[R any] func(ResponseData) (R, error)

ResponseConverter is a function type that converts ResponseData to a response of type R

type ResponseData

type ResponseData struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
}

ResponseData captures the HTTP response data

type ResponseWriter

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

ResponseWriter implements the http.ResponseWriter interface to capture HTTP responses

func NewResponse

func NewResponse() *ResponseWriter

NewResponse creates a new ResponseWriter instance.

func (*ResponseWriter) CloseNotify

func (w *ResponseWriter) CloseNotify() <-chan bool

CloseNotify notifies when the response is closed.

func (*ResponseWriter) Header

func (w *ResponseWriter) Header() http.Header

Header returns the header map that will be sent by WriteHeader.

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(b []byte) (int, error)

Write writes the data to the buffer.

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(statusCode int)

WriteHeader sends an HTTP response header with the provided status code.

Jump to

Keyboard shortcuts

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