-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
82 lines (70 loc) · 1.61 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
package main
import (
"bytes"
"flag"
"fmt"
amsgRPC "github.com/ARGOeu/ams-push-server/api/v1/grpc"
"github.com/ARGOeu/ams-push-server/config"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net"
)
func init() {
fmter := &log.TextFormatter{FullTimestamp: true, DisableColors: true}
log.SetFormatter(fmter)
}
func main() {
// Retrieve configuration file location from a cli argument
cfgPath := flag.String("config", "/etc/ams-push-server/conf.d/ams-push-server-config.json", "Path for the required configuration file.")
flag.Parse()
bCfg, err := ioutil.ReadFile(*cfgPath)
if err != nil {
log.WithFields(
log.Fields{
"type": "error_log",
"path": *cfgPath,
"error": err.Error(),
},
).Fatal("Could not read configuration file")
}
// initialize the config
cfg := new(config.Config)
err = cfg.LoadFromJson(bytes.NewReader(bCfg))
if err != nil {
log.WithFields(
log.Fields{
"type": "error_log",
"error": err.Error(),
},
).Fatal("Could not load configuration file")
}
log.SetLevel(cfg.GetLogLevel())
listener, err := net.Listen("tcp", fmt.Sprintf(":%v", cfg.ServicePort))
if err != nil {
log.WithFields(
log.Fields{
"type": "error_log",
"error": err.Error(),
},
).Fatal("Could not listen")
}
log.WithFields(
log.Fields{
"type": "service_log",
},
).Info("API is ready to start serving")
srv := amsgRPC.NewGRPCServer(cfg)
defer func() {
listener.Close()
srv.GracefulStop()
}()
err = srv.Serve(listener)
if err != nil {
log.WithFields(
log.Fields{
"type": "error_log",
"error": err.Error(),
},
).Fatal("Could not serve")
}
}