Documentation ¶
Index ¶
- func ListenAndServe(host string, h http.Handler)
- func NewContext(ctx context.Context, ev events.APIGatewayProxyRequest) context.Context
- func RequestContext(ctx context.Context) (events.APIGatewayProxyRequestContext, bool)
- type DefaultProxy
- type Gateway
- type Proxy
- type ProxyFunc
- type Request
- func (r *Request) AttachContext(req *http.Request)
- func (r *Request) CreateRequest(host string) (*http.Request, error)
- func (r *Request) ParseBody() error
- func (r *Request) ParseURL(host string) (*url.URL, error)
- func (r *Request) SetContentLength(req *http.Request)
- func (r *Request) SetCustomHeaders(req *http.Request)
- func (r *Request) SetHeaderFields(req *http.Request)
- func (r *Request) SetRemoteAddr(req *http.Request)
- func (r *Request) SetXRayHeader(req *http.Request)
- func (r *Request) StripBasePath(basePath string)
- type ResponseWriter
- type StripBasePathProxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe is a drop-in replacement for http.ListenAndServe for use within AWS Lambda.
func NewContext ¶
NewContext populates a context.Context from the http.Request with a request context provided in event from the AWS API Gateway proxy.
func RequestContext ¶
func RequestContext(ctx context.Context) (events.APIGatewayProxyRequestContext, bool)
RequestContext returns the APIGatewayProxyRequestContext value stored in ctx.
Types ¶
type DefaultProxy ¶
type DefaultProxy struct {
Host string
}
DefaultProxy is a default proxy for AWS API Gateway events
func (*DefaultProxy) Transform ¶
func (p *DefaultProxy) Transform(ctx context.Context, ev events.APIGatewayProxyRequest) (*http.Request, error)
Transform returns a new http.Request created from the given Lambda event.
type Gateway ¶
Gateway mimics the http.Server definition and takes care of proxying AWS Lambda event to http.Request via Proxy and then handling it using Handler
func NewGateway ¶
NewGateway creates new Gateway, which utilizes handler (or http.DefaultServeMux if nil passed) as a Gateway.Handler and apigo.http.DefaultProxy as a Gateway.Proxy.
func (*Gateway) ListenAndServe ¶
func (g *Gateway) ListenAndServe()
ListenAndServe registers a listener of AWS Lambda events.
func (*Gateway) Serve ¶
func (g *Gateway) Serve(ctx context.Context, e events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
Serve handles incoming event from AWS Lambda by wraping them into http.Request which is further processed by http.Handler to reply as a APIGatewayProxyResponse.
type Proxy ¶
type Proxy interface {
Transform(context.Context, events.APIGatewayProxyRequest) (*http.Request, error)
}
Proxy transforms an event and context provided from the API Gateway to the http.Request.
type ProxyFunc ¶
ProxyFunc implements the Proxy interface to allow use of ordinary function as a handler.
type Request ¶
type Request struct { Context context.Context Event events.APIGatewayProxyRequest Path string Body *bytes.Reader }
Request is an wrapper which helps transforming event from AWS API Gateway as a http.Request.
func NewRequest ¶
func NewRequest(ctx context.Context, ev events.APIGatewayProxyRequest) *Request
NewRequest defines new RequestBuilder with context and event data provided from the API Gateway.
func (*Request) AttachContext ¶
AttachContext attaches events' RequestContext to the http.Request.
func (*Request) CreateRequest ¶
CreateRequest provides *http.Request to the RequestBuilder.
func (*Request) SetContentLength ¶
SetContentLength sets Content-Length to the request if it has not been set.
func (*Request) SetCustomHeaders ¶
SetCustomHeaders assigns X-Request-Id and X-Stage from the event's Request Context.
func (*Request) SetHeaderFields ¶
SetHeaderFields sets headers to the request.
func (*Request) SetRemoteAddr ¶
SetRemoteAddr sets RemoteAddr to the request.
func (*Request) SetXRayHeader ¶
SetXRayHeader sets AWS X-Ray Trace ID from the event's context.
func (*Request) StripBasePath ¶
StripBasePath removes a BasePath from the Path fragment of the URL. StripBasePath must be run before RequestBuilder.ParseURL function.
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
ResponseWriter implements the http.ResponseWriter interface in order to support the API Gateway Lambda HTTP "protocol".
func NewResponse ¶
func NewResponse() *ResponseWriter
NewResponse returns a new response writer to capture http output.
func (*ResponseWriter) CloseNotify ¶
func (w *ResponseWriter) CloseNotify() <-chan bool
CloseNotify notify when the response is closed
func (*ResponseWriter) End ¶
func (w *ResponseWriter) End() events.APIGatewayProxyResponse
End the request.
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header() http.Header
Header implementation.
func (*ResponseWriter) Write ¶
func (w *ResponseWriter) Write(b []byte) (int, error)
Write implementation.
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(status int)
WriteHeader implementation.
type StripBasePathProxy ¶
func (*StripBasePathProxy) Transform ¶
func (p *StripBasePathProxy) Transform(ctx context.Context, ev events.APIGatewayProxyRequest) (*http.Request, error)