From 778a2f135a702f4f35e5c7d56a1694863d9aa999 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 27 Nov 2021 21:36:30 -0600 Subject: [PATCH] fix bugs that made it not compile lol --- main.go | 19 +++++++------------ shutdown.go | 5 +++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 3b1cb64..a50f967 100644 --- a/main.go +++ b/main.go @@ -16,17 +16,12 @@ var log_error = log.New(os.Stderr, "", 0) var log_info = log.New(os.Stdout, "", 0) func bail(status int, t string, args ...interface{}) { - if status != nil { + if status != 0 { shutdown(fmt.Errorf(t, args...)) } else { - log_info.Printf - } - out := log_info - if status != 0 { - out = log_error + log_info.Printf(t, args...) + shutdown(nil) } - out.Printf(t+"\n", args...) - shutdown(status) } //go:embed usage @@ -46,12 +41,12 @@ func run(o options) error { if err != nil { return fmt.Errorf("unable to open unix socket: %w", err) } - onShutdown(func() { l.Close() }) + onShutdown(func() error { return l.Close() }) server := http.Server{ Handler: new(handler), } - onShutdown(func() { server.Shutdown(nil) }) + onShutdown(func() error { return server.Shutdown(nil) }) // ?? start := time.Now() @@ -71,10 +66,10 @@ func sigCancel(ctx context.Context) context.Context { signal.Notify(c, os.Interrupt) ctx, cancel := context.WithCancel(ctx) - onShutdown(cancel) + onShutdown(func() error { cancel(); return nil }) go func() { <-c - shutdown() + shutdown(nil) }() return ctx } diff --git a/shutdown.go b/shutdown.go index 8f32caf..8a6a43c 100644 --- a/shutdown.go +++ b/shutdown.go @@ -2,9 +2,10 @@ package main import ( "sync" + "os" ) -var shutdownHandlers []func() +var shutdownHandlers []func() error var shutdownOnce sync.Once func shutdown(cause error) { @@ -25,6 +26,6 @@ func shutdown(cause error) { }) } -func onShutdown(f func()) { +func onShutdown(f func() error) { shutdownHandlers = append(shutdownHandlers, f) }