-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (37 loc) · 984 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
// Copyright © 2019 Valentin Slyusarev <[email protected]>
//go:generate afs -src=web/asset -rw
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/jessevdk/go-flags"
"github.com/va-slyusarev/lgr"
"github.com/va-slyusarev/pinky/app/cmd"
"github.com/va-slyusarev/pinky/app/config"
)
var revision = "develop"
func main() {
fmt.Printf("pinky: app: revision: %s\n", revision)
var p = flags.NewParser(&config.AppCfg, flags.Default)
if _, err := p.Parse(); err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
os.Exit(0)
} else {
os.Exit(1)
}
}
ctx, cancel := context.WithCancel(context.Background())
go func() {
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, os.Kill, syscall.SIGTERM)
<-stop
lgr.Warn("app: detect interrupt, terminate after few seconds...")
cancel()
}()
if err := cmd.Run(ctx); err != nil {
lgr.Error("app: terminated: %v", err)
}
}