Skip to content

Instantly share code, notes, and snippets.

@thomaspoignant
Last active February 18, 2021 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaspoignant/7563fde92386e3af3b2dc9e42d00b3b1 to your computer and use it in GitHub Desktop.
Save thomaspoignant/7563fde92386e3af3b2dc9e42d00b3b1 to your computer and use it in GitHub Desktop.
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