This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
83 lines (65 loc) · 2.3 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
package main
import (
"log"
"os"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/db/products"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/productcache"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/stand"
"github.com/kyma-incubator/bullseye-showcase/backend/pkg/mqtt"
"github.com/vrischmann/envconfig"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/db"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/db/attributes"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/db/questions"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/db/stands"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/ec"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/hardware"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/matching"
"github.com/kyma-incubator/bullseye-showcase/backend/internal/server"
)
// Config stores entire application configuration.
type Config struct {
EC ec.Config
Server server.Config
DB db.Config
HW mqtt.Config
}
func main() {
log.Println("Starting server...")
var config Config
err := envconfig.Init(&config)
if err != nil {
log.Println(err)
os.Exit(1)
}
log.Println("Config:", config)
database, err := db.New(&config.DB)
if err != nil {
log.Println(err)
}
standsRepo := stands.NewRepository(database)
attributesRepo := attributes.NewRepository(database)
questionsRepo := questions.NewRepository(database)
productsRepo := products.NewRepository(database)
productService := ec.NewProductService(&config.EC)
productCacheService := productcache.NewProductCacheService(productService, standsRepo, productsRepo)
standService := stand.NewStandService(productCacheService, standsRepo)
client, err := mqtt.FromConfig(&config.HW)
if err != nil {
log.Println(err)
}
defer func() {
err = client.Disconnect(config.HW.MQTT.Disconnect.Milliseconds)
if err != nil {
log.Println(err)
}
}()
hardwareService := hardware.NewHardwareService(client, standsRepo)
matcher := matching.NewService(standService, attributesRepo)
srv := server.NewServer(&config.Server, productCacheService, standsRepo, standService, matcher,
attributesRepo, hardwareService, questionsRepo)
err = srv.Start()
if err != nil {
log.Println(err)
os.Exit(1)
}
}