-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (33 loc) · 983 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func Handler(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
if req.HTTPMethod != "POST" {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusMethodNotAllowed,
Body: http.StatusText(http.StatusMethodNotAllowed),
}, nil
}
webhookBody := WebhookBody{}
if err := json.Unmarshal([]byte(req.Body), &webhookBody); err != nil {
log.Print(err)
log.Printf("%+v", req.Body) // Body is a string so can be reused
return events.APIGatewayProxyResponse{
StatusCode: http.StatusInternalServerError,
Body: http.StatusText(http.StatusInternalServerError),
}, nil
}
log.Printf("%+v", webhookBody)
return events.APIGatewayProxyResponse{
StatusCode: http.StatusAccepted,
Body: http.StatusText(http.StatusAccepted),
}, nil
}
func main() {
lambda.Start(Handler)
}