-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (46 loc) · 976 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 (
"coco-tool/config/conf"
"coco-tool/config/provider/etcd"
"coco-tool/config/repostory"
"coco-tool/config/web"
"errors"
"os"
"os/signal"
"syscall"
_ "coco-tool/config/provider"
"github.com/urfave/cli/v2"
)
var cancelFuncs = make([]func(), 0, 0)
func main() {
defer func() {
for _, cancel := range cancelFuncs {
cancel()
}
}()
app := &cli.App{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"f"},
Usage: "application config file",
},
},
Action: func(c *cli.Context) error {
if c.String("config") == "" {
return errors.New("config is empty")
}
cancelFuncs = append(cancelFuncs, conf.Init(c.String("config"))...)
cancelFuncs = append(cancelFuncs, web.Run())
etcd.Init()
repostory.Init()
return nil
},
}
if err := app.Run(os.Args); err != nil {
panic(err)
}
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
}