-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (51 loc) · 1.27 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
package main
import (
"context"
"net/http"
"github.com/calmato/gran/api/todo/config"
"github.com/calmato/gran/api/todo/lib/firebase"
"github.com/calmato/gran/api/todo/lib/firebase/authentication"
"github.com/calmato/gran/api/todo/lib/firebase/firestore"
"github.com/calmato/gran/api/todo/lib/firebase/storage"
"github.com/calmato/gran/api/todo/registry"
"google.golang.org/api/option"
)
func main() {
// ログ出力設定
config.Logger()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// 環境変数
e, err := config.LoadEnvironment()
if err != nil {
panic(err)
}
// Firebaseの初期化
opt := option.WithCredentialsFile(e.GoogleApplicationCredentials)
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)
}
reg := registry.NewRegistry(fa, fs, cs)
// サーバ起動
r := config.Router(reg)
if err = http.ListenAndServe(":"+e.Port, r); err != nil {
panic(err)
}
}