-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
91 lines (78 loc) · 1.95 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
84
85
86
87
88
89
90
91
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"os/signal"
"strings"
"syscall"
"time"
"code.vegaprotocol.io/liqbot/config"
"code.vegaprotocol.io/liqbot/service"
"github.com/jinzhu/configor"
log "github.com/sirupsen/logrus"
)
var (
// Version is set at build time using: -ldflags "-X main.Version=someversion".
Version = "no_version_set"
// VersionHash is set at build time using: -ldflags "-X main.VersionHash=somehash".
VersionHash = "no_hash_set"
)
func main() {
var configName string
var configVersion bool
flag.StringVar(&configName, "config", "", "Configuration YAML file")
flag.BoolVar(&configVersion, "version", false, "Show version")
flag.Parse()
if configVersion {
fmt.Printf("version %v (%v)\n", Version, VersionHash)
return
}
rand.Seed(time.Now().UnixNano())
var cfg config.Config
err := configor.Load(&cfg, configName)
// https://github.com/jinzhu/configor/issues/40
if err != nil && !strings.Contains(err.Error(), "should be struct") {
log.WithFields(log.Fields{
"error": err.Error(),
}).Fatal("Failed to read config")
}
err = config.CheckConfig(&cfg)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Fatal("Config checks failed")
}
err = config.ConfigureLogging(cfg.Server)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Fatal("Failed to load config")
}
log.WithFields(log.Fields{
"version": Version,
"hash": VersionHash,
}).Info("Version")
var s *service.Service
s, err = service.NewService(cfg, nil, nil)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Fatal("Failed to create service")
}
go func() {
err := s.Start()
if err != nil && err.Error() != "http: Server closed" {
log.WithFields(log.Fields{
"listen": cfg.Server.Listen,
"error": err.Error(),
}).Fatal("Could not listen")
}
}()
c := make(chan os.Signal, 2)
signal.Notify(c, syscall.SIGINT)
signal.Notify(c, syscall.SIGTERM)
<-c
s.Stop()
}