-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (61 loc) · 1.26 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
package main
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
"go-starter/config"
"go-starter/logger"
"go-starter/runner"
"github.com/urfave/cli"
)
func shutDown(shutDownChannel chan *bool) {
shutDown := true
shutDownChannel <- &shutDown
close(shutDownChannel)
}
// @title Go Starter API
// @version 0.0.1
// @description Go Starter API
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
func main() {
var shutDownChannel chan *bool
defer logger.Log.Sync()
app := cli.NewApp()
app.Name = config.Cfg.ServiceName
app.Version = config.Cfg.ServiceVersion
app.Commands = []cli.Command{
{
Name: "start",
Usage: "Start the api service",
Action: func(c *cli.Context) error {
logger.Log.Info("starting the api service")
ctx := context.Background()
var wg sync.WaitGroup
wg.Add(1)
go runner.NewAPI().Go(ctx, &wg)
wg.Wait()
return nil
},
},
}
if err := app.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)
}()
}