-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (63 loc) · 1.73 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
72
73
74
75
76
77
package main
import (
"context"
"net/http"
"github.com/calmato/presto-pay/api/user/config"
"github.com/calmato/presto-pay/api/user/lib/firebase"
"github.com/calmato/presto-pay/api/user/lib/firebase/authentication"
"github.com/calmato/presto-pay/api/user/lib/firebase/firestore"
"github.com/calmato/presto-pay/api/user/lib/firebase/storage"
"github.com/calmato/presto-pay/api/user/middleware"
"github.com/calmato/presto-pay/api/user/registry"
log "github.com/sirupsen/logrus"
"google.golang.org/api/option"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// ログ出力設定
config.Logger()
// 環境変数
e, err := config.LoadEnvironment()
if err != nil {
log.Panic(err)
}
// ログ転送設定の初期化
middleware.SetupFluent(e.FluentHost, e.FluentPort)
// Firebaseの初期化
// opt := option.WithCredentialsFile(e.GoogleApplicationCredentials)
opt := option.WithCredentialsJSON([]byte(e.GCPServiceKeyJSON))
fb, err := firebase.InitializeApp(ctx, nil, opt)
if err != nil {
panic(err)
}
// Firebase Authentication
fa, err := authentication.NewClient(ctx, fb.App)
if err != nil {
panic(err)
}
// Firestore
fs, err := firestore.NewClient(ctx, fb.App)
if err != nil {
panic(err)
}
defer fs.Close()
// Cloud Storage
cs, err := storage.NewClient(ctx, fb.App, e.GCPStorageBucketName)
if err != nil {
panic(err)
}
// メトリクス公開用サーバ起動
mr := config.MetricsRouter()
go func() {
if err := http.ListenAndServe(":"+e.MetricsPort, mr); err != nil {
log.Panic(err)
}
}()
reg := registry.NewRegistry(fa, fs, cs)
// サーバ起動
r := config.Router(reg)
if err := http.ListenAndServe(":"+e.Port, r); err != nil {
log.Panic(err)
}
}