-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (55 loc) · 1.04 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
package main
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
"soccer-manager/config"
"soccer-manager/instance"
"soccer-manager/runner"
"github.com/urfave/cli"
)
func shutDown(shutDownChannel chan *bool) {
shutDown := true
shutDownChannel <- &shutDown
close(shutDownChannel)
}
func main() {
config.Load()
instance.Init()
var shutDownChannel chan *bool
defer instance.Destroy()
clientApp := cli.NewApp()
clientApp.Name = "soccer-manager-app"
clientApp.Version = "0.0.1"
clientApp.Commands = []cli.Command{
{
Name: "start",
Usage: "Start the service",
Action: func(c *cli.Context) error {
ctx := context.Background()
var wg sync.WaitGroup
wg.Add(1)
go runner.NewAPI().Go(ctx, &wg)
wg.Wait()
return nil
},
},
}
if err := clientApp.Run(os.Args); err != nil {
panic(err)
}
signalChannel := make(chan os.Signal, 2)
signal.Notify(
signalChannel,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
)
go func() {
<-signalChannel
shutDown(shutDownChannel)
}()
}