-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (60 loc) · 1.67 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"fmt"
"os"
"sync"
"github.com/KuriharaYuya/yuya-kanshi-serverless/gateway"
notionpkg "github.com/KuriharaYuya/yuya-kanshi-serverless/repository/notion"
"github.com/KuriharaYuya/yuya-kanshi-serverless/repository/tweet"
utils "github.com/KuriharaYuya/yuya-kanshi-serverless/util"
"github.com/aws/aws-lambda-go/lambda"
"github.com/joho/godotenv"
)
// Response is of type APIGatewayProxyResponse since we're leveraging the
// AWS Lambda Proxy Request functionality (default behavior)
//
// https://serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-proxy-integration
// Handler is our lambda handler invoked by the `lambda.Start` function call
func Handler(ctx context.Context, req utils.Request) (utils.Response, error) {
var wg sync.WaitGroup
wg.Add(1)
// respをポインタ変数として定義
var resp *utils.Response
go func() {
resp = gateway.Gateway(req)
wg.Done()
}()
wg.Wait()
return *resp, nil
}
func init() {
if utils.ENVIRONMENT == "development" {
// ローカル開発環境用の処理
err := godotenv.Load()
if err != nil {
fmt.Printf("読み込み出来ませんでした_main.go: %v", err)
}
} else {
// 本番環境用の処理
// 例: AWS Secrets Managerから秘密情報を取得する
}
}
func main() {
debugMode := os.Getenv("DEBUG_MODE")
if debugMode == "true" {
// run some tgt funcs below
fmt.Println("debug mode")
var wg sync.WaitGroup
wg.Add(1)
go func() {
l, _ := notionpkg.ValidateLog("2023-11-03")
tweet.CallVercelTwitterAPI(&l)
defer wg.Done()
// リクエストをを全てunmarshalして表示する
}()
wg.Wait()
} else {
lambda.Start(Handler)
}
}