|
|
- package common
-
- import (
- "fmt"
- "os"
- "os/signal"
- )
-
- func TrapSignal(cb func()) {
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
- go func() {
- for sig := range c {
- fmt.Printf("captured %v, exiting...\n", sig)
- if cb != nil {
- cb()
- }
- os.Exit(1)
- }
- }()
- select {}
- }
|