Last active
February 18, 2021 12:57
-
-
Save thomaspoignant/7563fde92386e3af3b2dc9e42d00b3b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chiLambda *chiadapter.ChiLambda | |
// handler is the function called by the lambda. | |
func handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | |
return chiLambda.ProxyWithContext(ctx, req) | |
} | |
// main is called when a new lambda starts, so don't | |
// expect to have something done for every query here. | |
func main() { | |
// init go-chi router | |
r := chi.NewRouter() | |
r.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) { | |
body, _ := ioutil.ReadAll(r.Body) | |
_ = render.Render(w, r, &apiResponse{ | |
Status: http.StatusOK, | |
URL: r.URL.String(), | |
RequestBody: string(body), | |
}) | |
}) | |
chiLambda = chiadapter.New(r) | |
// start the lambda with a context | |
lambda.StartWithContext(context.Background(), handler) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment