handlersignal.go 493 B

1234567891011121314151617181920212223242526
  1. package util
  2. import (
  3. "os"
  4. "os/signal"
  5. "syscall"
  6. )
  7. // HandlerExit handler exit signal
  8. func HandlerExit(exitFn func(s os.Signal) int) {
  9. sch := make(chan os.Signal, 1)
  10. signal.Notify(sch, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  11. s := <-sch
  12. os.Exit(exitFn(s))
  13. }
  14. // HandlerReload handler Reload signal
  15. func HandlerReload(reload func(s os.Signal)) {
  16. go func() {
  17. sch := make(chan os.Signal, 1)
  18. signal.Notify(sch, syscall.SIGHUP)
  19. for s := range sch {
  20. reload(s)
  21. }
  22. }()
  23. }