-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
74 lines (57 loc) · 1.45 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
package main
import (
"context"
"crynux_relay/api"
"crynux_relay/config"
"crynux_relay/migrate"
"crynux_relay/tasks"
"fmt"
"os"
log "github.com/sirupsen/logrus"
)
func main() {
if err := config.InitConfig(""); err != nil {
print("Error reading config file")
print(err.Error())
os.Exit(1)
}
conf := config.GetConfig()
if err := config.InitLog(conf); err != nil {
print("Error initializing log")
print(err.Error())
os.Exit(1)
}
if err := config.InitDB(conf); err != nil {
log.Errorln(err.Error())
os.Exit(1)
}
startDBMigration()
go tasks.ProcessTasks(context.Background())
go tasks.StartSyncNetwork(context.Background())
go tasks.StartStatsTaskCount(context.Background())
go tasks.StartStatsTaskExecutionTimeCount(context.Background())
go tasks.StartStatsTaskUploadResultTimeCount(context.Background())
go tasks.StartStatsTaskWaitingTimeCount(context.Background())
startServer()
}
func startServer() {
conf := config.GetConfig()
app := api.GetHttpApplication(conf)
address := fmt.Sprintf("%s:%s", conf.Http.Host, conf.Http.Port)
log.Infoln("Starting application server...")
if err := app.Run(address); err != nil {
log.Errorln(err.Error())
os.Exit(1)
}
}
func startDBMigration() {
migrate.InitMigration(config.GetDB())
if err := migrate.Migrate(); err != nil {
log.Errorln(err.Error())
if err = migrate.Rollback(); err != nil {
log.Errorln(err.Error())
}
os.Exit(1)
}
log.Infoln("DB migrations are done!")
}