Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "log" "net/http" gateway "github.com/Drafteame/gateway/v2/apiv2" ) func main() { http.HandleFunc("/", hello) log.Fatal(gateway.ListenAndServe(nil)) } func hello(w http.ResponseWriter, r *http.Request) { _, _ = fmt.Fprintln(w, "Hello World from Go") }
Output:
Index ¶
- func ListenAndServe(h http.Handler, opts ...Option) error
- func NewRequest(ctx context.Context, e events.APIGatewayV2HTTPRequest) (*http.Request, error)
- func RequestContext(ctx context.Context) (events.APIGatewayV2HTTPRequestContext, bool)
- type Decorator
- type Gateway
- type Option
- type Options
- type ResponseWriter
Examples ¶
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.
ListenAndServe always returns a non-nil error.
func NewRequest ¶
NewRequest returns a new http.Request from the given Lambda event.
func RequestContext ¶
func RequestContext(ctx context.Context) (events.APIGatewayV2HTTPRequestContext, bool)
RequestContext returns the APIGatewayV2HTTPRequestContext value stored in ctx.
Types ¶
type Decorator ¶
type Decorator func(handler interface{}) interface{}
Decorator is a wrapper function that adds functionality to the current lambda handler.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway wrap a http handler to enable use as a lambda.Handler
func NewGateway ¶
NewGateway creates a gateway using the provided http.Handler enabling use in existing aws-lambda-go projects
func (*Gateway) Invoke ¶
func (gw *Gateway) Invoke(ctx context.Context, evt events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error)
Invoke Handler implementation
type Option ¶
type Option func(*Options)
Option is a callback that configure som handler option.
func WithDecorator ¶
WithDecorator adds a new decorator to the lambda handler configuration.
type Options ¶
type Options struct {
Decorators []Decorator
}
Options represents all options that can be applied to the lambda handler.
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.APIGatewayV2HTTPResponse
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.