Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"net/http"
"strconv"
goapigatewaylambdaconnector "github.com/anthonyLock/go-api-gateway-lambda-connector"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("index"))
}
func addHandler(w http.ResponseWriter, r *http.Request) {
f, _ := strconv.Atoi(r.FormValue("first"))
s, _ := strconv.Atoi(r.FormValue("second"))
w.Header().Set("X-Hi", "foo")
fmt.Fprintf(w, "%d", f+s)
}
func contextHandler(w http.ResponseWriter, r *http.Request) {
proxyReq, ok := goapigatewaylambdaconnector.ProxyRequestFromContext(r.Context())
if ok {
fmt.Fprint(w, proxyReq.RequestContext.AccountID)
}
}
func main() {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/add", addHandler)
http.HandleFunc("/context", contextHandler)
goapigatewaylambdaconnector.ListenAndServe(http.DefaultServeMux, nil)
}
Index ¶
- func APIGatewayV2HTTPRequestFromContext(ctx context.Context) (events.APIGatewayV2HTTPRequest, bool)
- func ListenAndServe(handler http.Handler, opts *Options)
- func ProxyRequestFromContext(ctx context.Context) (events.APIGatewayProxyRequest, bool)
- func TargetGroupRequestFromContext(ctx context.Context) (events.ALBTargetGroupRequest, bool)
- type Options
- type RequestType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIGatewayV2HTTPRequestFromContext ¶
func APIGatewayV2HTTPRequestFromContext(ctx context.Context) (events.APIGatewayV2HTTPRequest, bool)
APIGatewayV2HTTPRequestFromContext extracts the APIGatewayV2HTTPRequest event from ctx.
func ListenAndServe ¶
ListenAndServe starts the AWS Lambda runtime (aws-lambda-go lambda.Start) with a given handler.
func ProxyRequestFromContext ¶
func ProxyRequestFromContext(ctx context.Context) (events.APIGatewayProxyRequest, bool)
ProxyRequestFromContext extracts the APIGatewayProxyRequest event from ctx.
func TargetGroupRequestFromContext ¶
func TargetGroupRequestFromContext(ctx context.Context) (events.ALBTargetGroupRequest, bool)
TargetGroupRequestFromContext extracts the ALBTargetGroupRequest event from ctx.
Types ¶
type Options ¶
type Options struct {
// RequestType sets the expected request type.
// By default algnhsa deduces the request type from the lambda function payload.
RequestType RequestType
// BinaryContentTypes sets content types that should be treated as binary types.
// The "*/* value makes algnhsa treat any content type as binary.
BinaryContentTypes []string
// Use API Gateway PathParameters["proxy"] when constructing the request url.
// Strips the base path mapping when using a custom domain with API Gateway.
UseProxyPath bool
// contains filtered or unexported fields
}
Options holds the optional parameters.
type RequestType ¶
type RequestType int
const ( RequestTypeAuto RequestType = iota RequestTypeAPIGateway RequestTypeAPIGatewayV2 RequestTypeALB )
Click to show internal directories.
Click to hide internal directories.

