-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (40 loc) · 995 Bytes
/
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
package main
import (
"context"
"time"
"github.com/Phillezi/test-psql-conn/config"
"github.com/Phillezi/test-psql-conn/internal/client"
"github.com/Phillezi/test-psql-conn/internal/models"
"github.com/Phillezi/test-psql-conn/internal/server"
"github.com/Phillezi/test-psql-conn/util"
_ "github.com/lib/pq"
"github.com/sirupsen/logrus"
)
func main() {
cfg := config.Load()
defer func() {
if cfg.SleepWhenDone {
sleepInf()
}
}()
if cfg.DBUser == "" || cfg.DBPass == "" || cfg.DBName == "" {
logrus.Errorln("DB_USER, DB_PASS and DB all have to be set")
util.LogEnvTable()
return
}
cfg.LogConfig()
connStatus := make(chan bool)
tablesChan := make(chan []models.Table)
srv := server.New(context.Background(), 8080, connStatus, tablesChan)
db := client.New(cfg, connStatus, tablesChan)
if cfg.ServeHTTP {
go srv.Start()
}
db.Start()
}
func sleepInf() {
logrus.Infoln("Sleeping forever since program exited")
for {
time.Sleep(100000 * time.Hour)
}
}