From 4b4a6952d77d4c4e5b3189c0e947697eb3eca926 Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Sun, 8 Sep 2024 22:06:16 +0200 Subject: feat: replace signal handler Go added signal.NotifyContext to the standard library in 1.16, allowing for easy bindings of signals to context. This allows for controller-runtime's signals.SetupSignalHandler to be replaced. --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 3c123d2..4546ede 100644 --- a/main.go +++ b/main.go @@ -4,12 +4,14 @@ package main import ( + "context" "flag" "log/slog" "net" "net/http" "net/http/pprof" "os" + "os/signal" "strconv" "time" @@ -18,7 +20,6 @@ import ( "go.terinstock.com/cgit-httpd/handlers/git" "go.terinstock.com/cgit-httpd/manager" "go.terinstock.com/cgit-httpd/server" - "sigs.k8s.io/controller-runtime/pkg/manager/signals" ) var configFile string @@ -89,7 +90,9 @@ func main() { }) } - if err := m.Start(signals.SetupSignalHandler()); err != nil { + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer cancel() + if err := m.Start(ctx); err != nil { logger.Info("manager stopped", "error", err) } } -- cgit v1.2.3