-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (57 loc) · 1.46 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
package main
import (
"fmt"
"os"
"datapaddock.lan/go_server/internal/server/http"
"datapaddock.lan/go_server/internal/utils/database"
"datapaddock.lan/go_server/internal/configs"
"datapaddock.lan/go_server/internal/devices"
"datapaddock.lan/go_server/internal/measurements"
)
func main() {
fmt.Println("Hello World")
var databaseCfg = new(database.Config)
var httpCfg = new(http.Config)
cfg, err := configs.New()
if err != nil {
//use hardcoded cfg
databaseCfg, err = cfg.Database()
if err != nil {
fmt.Println("db config creation failed")
}
httpCfg, err = cfg.HTTP()
if err != nil {
fmt.Println("config creation failed")
os.Exit(0)
}
} else {
httpCfg = cfg.HttpCfg
databaseCfg = cfg.DatabaseCfg
}
pool, err := database.NewService(databaseCfg)
if err != nil {
fmt.Println("pgxpool start failed")
}
deviceStore, err := devices.NewStore(pool)
if err != nil {
fmt.Println("deviceStore failed")
}
deviceService, err := devices.NewService(deviceStore)
if err != nil {
fmt.Println("deviceService failed")
}
measurementStore, err := measurements.NewStore(pool)
if err != nil {
fmt.Println("measurementStore failed")
}
measurementService, err := measurements.NewService(measurementStore)
if err != nil {
fmt.Println("measurementService failed")
}
http_server, err := http.NewService(httpCfg, measurementService, deviceService)
if err != nil {
fmt.Println("http server start failed")
os.Exit(0)
}
http_server.Start()
}