Last active
December 20, 2022 13:25
-
-
Save warlock/41631c571afa4101b8abedc054e7c831 to your computer and use it in GitHub Desktop.
golang-exit-signals.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func handleExit( | |
sigs <-chan os.Signal, | |
cancelFunc context.CancelFunc, | |
logger log.Logger, | |
shutDownManager synched_shutdown.WorkManager, | |
) { | |
sig := <-sigs | |
logger.WithFields(log.Fields{"type": serviceName, "subtype": "shutdown"}). | |
Infof("received signal %s", sig.String()) | |
cancelFunc() | |
shutDownManager.Wait() | |
} | |
func main() { | |
signals := make(chan os.Signal, 1) | |
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT) | |
shutdownManager := synched_shutdown.NewWorkManager() | |
ctx, cancel := context.WithCancel(context.Background()) | |
/// CODI AQUI | |
handleExit(signals, cancel, logger, shutdownManager) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment