summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-07 21:43:28 +0200
committerxengineering <me@xengineering.eu>2024-05-07 21:43:28 +0200
commit0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a (patch)
treec53cf3d4c398495775edf305687cce23198b3aba
parent5b3f0a81abea93b198825b5537297f3f04d1f7c1 (diff)
downloadceres-0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a.tar
ceres-0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a.tar.zst
ceres-0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a.zip
Introduce await() function
This improves readability of the main() function.
-rw-r--r--main.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/main.go b/main.go
index 6da8e93..84a0761 100644
--- a/main.go
+++ b/main.go
@@ -42,9 +42,14 @@ func main() {
go server.Start()
defer server.Stop()
+ await(syscall.SIGTERM, syscall.SIGINT)
+}
+
+func await(signals ...syscall.Signal) {
listener := make(chan os.Signal)
- signal.Notify(listener, syscall.SIGTERM)
- signal.Notify(listener, syscall.SIGINT)
+ for _, s := range signals {
+ signal.Notify(listener, s)
+ }
sig := <-listener
- log.Printf("Cleaning up due to OS signal '%v'\n", sig)
+ log.Printf("Received OS signal '%v'\n", sig)
}