generated from habedi/template-go-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
29 lines (23 loc) · 737 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
package main
import (
"github.com/habedi/template-go-project/cmd"
"os"
"os/signal"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
// send all logs to stdout
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
// This block sets up a go routine to listen for an interrupt signal which will immediately exit the program
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, os.Interrupt)
go listenForInterrupt(stopChan)
// Execute the CLI program
cmd.Execute()
}
// listenForInterrupt listens for an interrupt signal and exits the program when it is received
func listenForInterrupt(stopScan chan os.Signal) {
<-stopScan
log.Fatal().Msg("Interrupt signal received. Exiting...")
}