-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (71 loc) · 1.82 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
92
93
94
package main
import (
"os"
"os/signal"
"runtime"
"syscall"
"github.com/calaos/calaos-os-releases/app"
"github.com/calaos/calaos-os-releases/config"
"github.com/calaos/calaos-os-releases/models"
logger "github.com/calaos/calaos-os-releases/log"
"github.com/fatih/color"
cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
)
const (
DefaultConfigFilename = "/etc/calaos-os-releases.toml"
CharStar = "\u2737"
CharAbort = "\u2718"
CharCheck = "\u2714"
CharWarning = "\u26A0"
CharArrow = "\u2012\u25b6"
CharVertLine = "\u2502"
)
var (
blue = color.New(color.FgBlue).SprintFunc()
errorRed = color.New(color.FgRed).SprintFunc()
errorBgRed = color.New(color.BgRed, color.FgBlack).SprintFunc()
green = color.New(color.FgGreen).SprintFunc()
cyan = color.New(color.FgCyan).SprintFunc()
bgCyan = color.New(color.FgWhite).SprintFunc()
logging *logrus.Entry
myApp *app.AppServer
)
func exit(err error, exit int) {
logging.Fatalln(errorRed(CharAbort), err)
cli.Exit(exit)
}
func handleSignals() {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-sigint
logging.Println("Shuting down...")
myApp.Shutdown()
models.Shutdown()
}
func main() {
logging = logger.NewLogger("calaos-os-releases")
runtime.GOMAXPROCS(runtime.NumCPU())
a := cli.App("calaos-os-releases", "Calaos-OS Releases")
a.Spec = "[-c]"
var (
conffile = a.StringOpt("c config", DefaultConfigFilename, "Set config file")
)
a.Action = func() {
var err error
if err = config.InitConfig(conffile); err != nil {
exit(err, 1)
}
if myApp, err = app.NewApp(); err != nil {
exit(err, 1)
}
if err = models.Init(); err != nil {
exit(err, 1)
}
myApp.Start()
handleSignals()
}
if err := a.Run(os.Args); err != nil {
exit(err, 1)
}
}