From e6fe1b3e0c59506f6b87e85f80a85b9f4325e79d Mon Sep 17 00:00:00 2001 From: uditaren Date: Thu, 11 Apr 2024 11:07:26 +0200 Subject: [PATCH] Migrate to go.mod --- README.md | 6 ++++-- go.mod | 3 +++ terminator.go | 21 +++++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 go.mod diff --git a/README.md b/README.md index 6269fa8..1c17b89 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ -# terminator +terminator +========== + +The terminator module provides a clean way to react to Ctrl-C, SIGTERM, etc. -The go way of handling ctrl-c, sigterm, etc. \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7a2ace9 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module udico.de/util/terminator + +go 1.22.1 diff --git a/terminator.go b/terminator.go index 13a13b2..bb28b05 100644 --- a/terminator.go +++ b/terminator.go @@ -1,19 +1,28 @@ -package terminator /* import "udico.de/uditaren/terminator" */ +// Package terminator provides a simple way to await process termination. +// +// Just wait until the Terminate channel closes: +// +// <-terminator.Terminate +// +// it will fall through, once your process receives Ctrl-C, SIGINT, SIGTERM or SIGKILL signal. +package terminator import ( - "os" + "os" "os/signal" "syscall" ) -// enable to react to -// <-terminator.Terminate +// enable to react to +// +// <-terminator.Terminate +// // nicely var Terminate = make(chan struct{}) func init() { - sigs := make(chan os.Signal) - signal.Notify(sigs, os.Interrupt, os.Kill) + sigs := make(chan os.Signal) + signal.Notify(sigs, os.Interrupt, os.Kill) signal.Notify(sigs, syscall.SIGTERM) // When notified about SIGINT, SIGTERM, or SIGKILL close the Terminator channel