-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (28 loc) · 813 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
package main
import (
"context"
"log/slog"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
ginadapter "github.com/awslabs/aws-lambda-go-api-proxy/gin"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
var ginLambda *ginadapter.GinLambda
func Handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
if ginLambda == nil {
slog.Info("Gin cold start")
r := gin.Default()
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(cors.Default())
r.GET("/wakkason-demo-api/users", GetUsers)
r.POST("/wakkason-demo-api/message", PostMessage)
r.POST("/wakkason-demo-api/memory", PostMemory)
ginLambda = ginadapter.New(r)
}
return ginLambda.ProxyWithContext(ctx, req)
}
func main() {
lambda.Start(Handler)
}