From 0e9f498baaba549788f3c90c1396d37fdcb5c45e Mon Sep 17 00:00:00 2001 From: JamesJJ Date: Sat, 13 Mar 2021 12:30:15 +0800 Subject: [PATCH] Improve Go code example --- doc_source/services-apigateway-code.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/doc_source/services-apigateway-code.md b/doc_source/services-apigateway-code.md index 594b4580..c8d5fd7a 100644 --- a/doc_source/services-apigateway-code.md +++ b/doc_source/services-apigateway-code.md @@ -119,11 +119,19 @@ The following example processes messages from API Gateway, and logs information **Example LambdaFunctionOverHttps\.go** ``` +package main + import ( - "strings" + "context" + "fmt" "github.com/aws/aws-lambda-go/events" + runtime "github.com/aws/aws-lambda-go/lambda" ) +func main() { + runtime.Start(handleRequest) +} + func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { fmt.Printf("Processing request data for request %s.\n", request.RequestContext.RequestID) fmt.Printf("Body size = %d.\n", len(request.Body)) @@ -133,7 +141,7 @@ func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) ( fmt.Printf(" %s: %s\n", key, value) } - return events.APIGatewayProxyResponse { Body: request.Body, StatusCode: 200 }, nil + return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil } ```