Skip to content
Snippets Groups Projects
Commit 6ae5500c authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Pass in context and dont return sqs status code

parent 18fc59ea
No related branches found
No related tags found
Loading
......@@ -18,7 +18,7 @@ import (
// HTTP functions
// ========================================================================
func ServeHTTPFunctions(lambdaHandler lambda.Handler, w http.ResponseWriter, req *http.Request) {
func ServeHTTPFunctions(ctx context.Context, lambdaHandler lambda.Handler, w http.ResponseWriter, req *http.Request) {
// Read body
buf := new(bytes.Buffer)
......@@ -46,7 +46,6 @@ func ServeHTTPFunctions(lambdaHandler lambda.Handler, w http.ResponseWriter, req
}
jsonRequest, _ := json.Marshal(request)
ctx := context.Background()
responseBytes, err := lambdaHandler.Invoke(ctx, jsonRequest)
if err != nil {
panic(err)
......@@ -68,7 +67,7 @@ func ServeHTTPFunctions(lambdaHandler lambda.Handler, w http.ResponseWriter, req
// SQS Functions
// ========================================================================
func ServeSQSFunctions(lambdaHandler lambda.Handler, w http.ResponseWriter, req *http.Request) {
func ServeSQSFunctions(ctx context.Context, lambdaHandler lambda.Handler, w http.ResponseWriter, req *http.Request) {
// Read body
buf := new(bytes.Buffer)
......@@ -97,7 +96,6 @@ func ServeSQSFunctions(lambdaHandler lambda.Handler, w http.ResponseWriter, req
},
})
ctx := context.Background()
responseBytes, err := lambdaHandler.Invoke(ctx, sqsRequest)
if err != nil {
panic(err)
......@@ -107,10 +105,9 @@ func ServeSQSFunctions(lambdaHandler lambda.Handler, w http.ResponseWriter, req
response := map[string]any{}
err = json.Unmarshal(responseBytes, &response)
if err != nil {
_, _ = io.WriteString(w, err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(int(response["statusCode"].(float64)))
_, _ = io.WriteString(w, response["body"].(string))
_, _ = io.WriteString(w, "done")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment