-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 939 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
42
43
44
45
46
package main
import (
"context"
"fmt"
"mlogreport/app/config"
"mlogreport/app/database"
"mlogreport/app/route"
"mlogreport/app/storage"
"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 init() {
gin.SetMode(gin.ReleaseMode)
}
func main() {
cfg := config.InitConfig()
g := gin.Default()
db := database.InitDBPostgres(cfg)
database.DBMigration(db)
sb := storage.InitStorage(cfg)
g.Use(cors.Default())
route.Run(g, db, sb)
if cfg.MODE == "production" {
ginLambda = ginadapter.New(g)
lambda.Start(Handler)
} else {
g.Run(fmt.Sprintf(":%s", cfg.SERVERPORT))
}
}
func Handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return ginLambda.ProxyWithContext(ctx, req)
}