-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
38 lines (31 loc) · 648 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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/PanGan21/auctionplace/cmd/command"
)
const CANCEL_TIMEOUT = 3
func main() {
ctx, cancel := context.WithCancel(context.Background())
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
defer func() {
fmt.Println("Closing the app..")
signal.Stop(signals)
cancel()
}()
go func() {
<-signals
fmt.Println("Sending cancel signal..")
time.Sleep(CANCEL_TIMEOUT * time.Second)
os.Exit(1)
}()
cmd := command.NewRootCommand(ctx)
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}