/
repo.go
44 lines (37 loc) · 1.27 KB
/
repo.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
package app
import (
"context"
"time"
"github.com/reearth/reearth-marketplace/server/internal/infrastrcture/gcs"
mongorepo "github.com/reearth/reearth-marketplace/server/internal/infrastrcture/mongo"
"github.com/reearth/reearth-marketplace/server/internal/usecase/gateway"
"github.com/reearth/reearth-marketplace/server/internal/usecase/repo"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/mongox"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func initReposAndGateways(ctx context.Context, conf *Config, debug bool) (*repo.Container, *gateway.Container) {
repos := &repo.Container{}
gateways := &gateway.Container{}
// Mongo
client, err := mongo.Connect(
ctx,
options.Client().
ApplyURI(conf.DB).
SetConnectTimeout(time.Second*10),
)
if err != nil {
log.Fatalf("repo initialization error: %+v\n", err)
}
if err := mongorepo.InitRepos(ctx, repos, client, "reearth_marketplace", mongox.IsTransactionAvailable(conf.DB)); err != nil {
log.Fatalf("Failed to init mongo: %+v\n", err)
}
// File (GCS)
fileRepo, err := gcs.NewFile(conf.GCS.Bucket, conf.GCS.AssetsBucket, conf.GCS.AssetsBaseURL)
if err != nil {
log.Fatalf("file: init error: %v", err)
}
gateways.File = fileRepo
return repos, gateways
}