diff options
author | xengineering <me@xengineering.eu> | 2024-05-07 21:43:28 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-05-07 21:43:28 +0200 |
commit | 0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a (patch) | |
tree | c53cf3d4c398495775edf305687cce23198b3aba | |
parent | 5b3f0a81abea93b198825b5537297f3f04d1f7c1 (diff) | |
download | ceres-0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a.tar ceres-0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a.tar.zst ceres-0368b6d0f7069be078ca6dba2c8bb3ed06d9f03a.zip |
Introduce await() function
This improves readability of the main() function.
-rw-r--r-- | main.go | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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) } |