-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (82 loc) · 2.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"github.com/gorilla/mux"
"go.uber.org/dig"
"os"
"sealway-strava/infrastructure"
"sealway-strava/interfaces/graph"
"sealway-strava/interfaces/rest"
"sealway-strava/internal"
"sealway-strava/pkg/closer"
"sealway-strava/pkg/env"
"sealway-strava/pkg/graceful"
"sealway-strava/pkg/logger"
"sealway-strava/repository"
"sealway-strava/usecase"
"strconv"
"time"
)
var connectionString = env.EnvOrDefault("MONGO_CONNECTION", "mongodb://localhost:27017")
var stravaClientId = os.Getenv("STRAVA_CLIENT")
var stravaSecretId = os.Getenv("STRAVA_SECRET")
var activityBatchSize, _ = strconv.Atoi(env.EnvOrDefault("ACTIVITY_BATCH_SIZE", "50"))
var activityBatchTime, _ = time.ParseDuration(env.EnvOrDefault("ACTIVITY_BATCH_TIME", "45s"))
var port = env.EnvOrDefault("PORT", "8080")
var applicationSlug = env.EnvOrDefault("SLUG", "integration-strava")
func main() {
container := setupContainer()
err := container.Invoke(func(application graceful.Application) {
application.RunAndWait()
})
if err != nil {
panic(err)
}
}
func setupContainer() *dig.Container {
container := dig.New()
panicOrProvide(container, func() *usercase.BatchConfig {
return &usercase.BatchConfig{
ActivityBatchSize: activityBatchSize,
ActivityBatchTime: activityBatchTime,
}
})
panicOrProvide(container, func() *rest.ApiConfig {
return &rest.ApiConfig{
ApplicationSlug: applicationSlug,
Router: mux.NewRouter(),
}
})
panicOrProvide(container, func() *internal.ServerConfig {
return &internal.ServerConfig{
Port: port,
}
})
panicOrProvide(container, func() *infrastructure.StravaConfig {
return &infrastructure.StravaConfig{
ClientId: stravaClientId,
SecretId: stravaSecretId,
}
})
panicOrProvide(container, func() *repository.MongoConfig {
return &repository.MongoConfig{
ConnectionString: connectionString,
}
})
panicOrProvide(container, usercase.MakeSubscriptionManager)
panicOrProvide(container, usercase.MakeStravaService)
panicOrProvide(container, infrastructure.MakeStravaClient)
panicOrProvide(container, repository.MakeStravaRepository)
panicOrProvide(container, usercase.MakeBackgroundWorker)
panicOrProvide(container, rest.MakeRestApi)
panicOrProvide(container, rest.MakeSubscriptionApi)
panicOrProvide(container, graph.MakeGraphqlApi)
panicOrProvide(container, closer.MakeCloserCollection)
panicOrProvide(container, internal.MakeApplication)
return container
}
func panicOrProvide(container *dig.Container, constructor interface{}, opts ...dig.ProvideOption) {
err := container.Provide(constructor, opts...)
if err != nil {
logger.Fatalf("container.Provide: $v", err)
}
}