Documentation
¶
Index ¶
- func ConvertAPIGatewayProxyRequest(ctx context.Context, e events.APIGatewayProxyRequest) (*http.Request, error)
- func ConvertAPIGatewayV2HTTPRequest(ctx context.Context, e events.APIGatewayV2HTTPRequest) (*http.Request, error)
- func ConvertResponseV1(data ResponseData) (events.APIGatewayProxyResponse, error)
- func ConvertResponseV2(data ResponseData) (events.APIGatewayV2HTTPResponse, error)
- func ListenAndServe[T any, R any](addr string, handler http.Handler, requestConverter RequestConverter[T], ...) error
- func NewContext[T any](ctx context.Context, e T) context.Context
- func RequestContext[T any](ctx context.Context) (T, bool)
- type Gateway
- type Key
- type RequestConverter
- type ResponseConverter
- type ResponseData
- type ResponseWriter
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 ¶
NewContext returns a new Context with the API Gateway proxy RequestContext.
Types ¶
type Gateway ¶
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
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 ¶
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 ¶
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.