-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (52 loc) · 1.16 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
package main
import (
"os"
"flag"
"syscall"
"context"
"os/signal"
"github.com/dutchis/looking-glass/api"
"github.com/dutchis/looking-glass/config"
"github.com/spf13/viper"
"github.com/sirupsen/logrus"
)
var (
configuration config.Config
log = logrus.New()
errChan = make(chan error)
)
func init() {
log.Info("Starting...")
configPath := flag.String("config", "config.yaml", "Full path to your config file")
flag.Parse()
cfg, err := config.LoadConfig(configPath)
if err != nil {
log.WithError(err).Fatal("Failed to load config file")
}
configuration = cfg
log.Info("Read config file successfully")
if (viper.GetBool("debug")) {
log.SetLevel(logrus.DebugLevel)
} else {
log.SetLevel(logrus.InfoLevel)
}
log.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
}
func main() {
go func () {
for {
select {
case err := <-errChan:
log.WithError(err).Error("An error occurred")
}
}
}()
stopCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
apiServer := api.New(log, stopCtx, errChan, configuration.API)
go apiServer.Start()
<-stopCtx.Done()
log.Info("Exited")
}