diff options
author | 2024-09-08 22:06:16 +0200 | |
---|---|---|
committer | 2024-09-08 22:06:16 +0200 | |
commit | 4b4a6952d77d4c4e5b3189c0e947697eb3eca926 (patch) | |
tree | 9bf3878af861eb16bf0e210f3a96d3564ba11037 /main.go | |
parent | feat: use slog for logging (diff) | |
download | cgit-httpd-4b4a6952d77d4c4e5b3189c0e947697eb3eca926.tar.xz |
feat: replace signal handlerv0.5.0
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.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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) } } |