Documentation
¶
Overview ¶
Package gateway provides a drop-in replacement for net/http.ListenAndServe for use in AWS Lambda & API Gateway.
Example ¶
package main
import (
"fmt"
"log"
"net/http"
"github.com/carlmjohnson/gateway"
)
func main() {
http.HandleFunc("/", hello)
log.Fatal(gateway.ListenAndServe(":3000", nil))
}
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello World from Go")
}
Output:
Index ¶
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. Because the standard addr string is not used, it is replaced with host, which API Gateway does not always send with events.
ListenAndServe never returns.
func NewRequest ¶
NewRequest returns a new http.Request from the given Lambda event.
func RequestContext ¶
func RequestContext(ctx context.Context) (events.APIGatewayProxyRequestContext, bool)
RequestContext returns the APIGatewayProxyRequestContext value stored in ctx.
Types ¶
type ResponseWriter ¶
type ResponseWriter = gateway.ResponseWriter
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.