forked from diggerhq/gitlab-webhook-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fn.go
29 lines (24 loc) · 716 Bytes
/
fn.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
package main
import (
"context"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"os"
)
func GenerateResponse(Body string, Code int) events.APIGatewayProxyResponse {
return events.APIGatewayProxyResponse{Body: Body, StatusCode: Code}
}
func HandleRequest(_ context.Context, request events.LambdaFunctionURLRequest) (events.APIGatewayProxyResponse, error) {
fmt.Printf("Body: %s", request.Body)
secretToken := os.Getenv("SECRET_TOKEN")
err := ParseWebHookJSON(secretToken, request)
if err != nil {
fmt.Printf("error: %v\n", err)
return GenerateResponse(err.Error(), 500), nil
}
return GenerateResponse("", 200), nil
}
func main() {
lambda.Start(HandleRequest)
}