Documentation
¶
Overview ¶
Package shim provides a thin layer between the Lambda API Gateway integrations and the standard library `http.Handler` interface. Bring your own router.
Index ¶
- func NewAPIGatewayProxyResponse(rw *ResponseWriter) events.APIGatewayProxyResponse
- func NewApiGatewayV2HttpResponse(rw *ResponseWriter) events.APIGatewayV2HTTPResponse
- func NewHttpRequestFromAPIGatewayProxyRequest(ctx context.Context, event events.APIGatewayProxyRequest) (*http.Request, error)
- func NewHttpRequestFromAPIGatewayV2HTTPRequest(ctx context.Context, event events.APIGatewayV2HTTPRequest) (*http.Request, error)
- func SetDebugLogger(l Log) func(*Shim)
- func SetDebugWithSlog(l slog.Logger) func(*Shim)
- type Log
- type ResponseWriter
- type Shim
- func (s *Shim) Handle(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
- func (s *Shim) HandleHttpApiRequests(ctx context.Context, request events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error)
- func (s *Shim) HandleRestApiRequests(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAPIGatewayProxyResponse ¶
func NewAPIGatewayProxyResponse(rw *ResponseWriter) events.APIGatewayProxyResponse
NewAPIGatewayProxyResponse converts a shim.ResponseWriter into an events.APIGatewayProxyResponse
func NewApiGatewayV2HttpResponse ¶ added in v1.1.0
func NewApiGatewayV2HttpResponse(rw *ResponseWriter) events.APIGatewayV2HTTPResponse
func NewHttpRequestFromAPIGatewayProxyRequest ¶ added in v1.1.0
func NewHttpRequestFromAPIGatewayProxyRequest(ctx context.Context, event events.APIGatewayProxyRequest) (*http.Request, error)
NewHttpRequestFromAPIGatewayProxyRequest creates an *http.Request from a context.Context and an events.APIGatewayProxyRequest
func NewHttpRequestFromAPIGatewayV2HTTPRequest ¶ added in v1.1.0
func NewHttpRequestFromAPIGatewayV2HTTPRequest(ctx context.Context, event events.APIGatewayV2HTTPRequest) (*http.Request, error)
NewHttpRequestFromAPIGatewayV2HTTPRequest creates an *http.Request from the context passed from the Lambda library, and the event itself.
func SetDebugLogger ¶
SetDebugLogger is an option function to set the debug logger on a Shim. The debug logger gives insight into the event received from APIGateway and how shim transforms the request and response.
func SetDebugWithSlog ¶ added in v1.1.0
Types ¶
type Log ¶
type Log interface {
Printf(format string, v ...interface{})
}
Log is a simple logging interface that is satisfied by the standard library logger amongst other idiomatic loggers
type ResponseWriter ¶
ResponseWriter adheres to the http.ResponseWriter interface and makes the HTTP Status Code, Headers, and Body publicly accessible
func NewResponseWriter ¶
func NewResponseWriter() *ResponseWriter
NewResponseWriter returns an ResponseWriter with the headers properly initialized
func (*ResponseWriter) Header ¶
func (rw *ResponseWriter) Header() http.Header
Header adheres the http.ResponseWriter interface
func (*ResponseWriter) Write ¶
func (rw *ResponseWriter) Write(b []byte) (int, error)
Write adheres to the io.Writer interface
func (*ResponseWriter) WriteHeader ¶
func (rw *ResponseWriter) WriteHeader(c int)
WriteHeader adheres to the http.ResponseWriter interface
type Shim ¶
Shim provides a thin layer between your traditional http.Handler based application and AWS Lambda + API Gateway.
func New ¶
New returns an initialized Shim with the provided http.Handler. If no http.Handler is provided New will use http.DefaultServiceMux
func (*Shim) Handle ¶
func (s *Shim) Handle(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
Handle converts an APIGatewayProxyRequest converts an APIGatewayProxyRequest into an http.Request and passes it to the given http.Handler along with a ResponseWriter. The response from the handler is converted into an APIGatewayProxyResponse.
func (*Shim) HandleHttpApiRequests ¶ added in v1.1.0
func (s *Shim) HandleHttpApiRequests(ctx context.Context, request events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error)
HandleHttpApiRequests converts an APIGatewayV2HTTPRequest into an http.Request and passes it to the http.Handler. Http responses are converted into APIGatewayV2HTTPResponse
func (*Shim) HandleRestApiRequests ¶ added in v1.1.0
func (s *Shim) HandleRestApiRequests(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
HandleRestApiRequests converts an APIGatewayProxyRequest into an http.Request and passes it to the http.Handler. Http responses are converted into APIGatewayProxyResponse.