fix bugs that made it not compile lol

master
Jordan Orelli 3 years ago
parent dbeba4fa94
commit 778a2f135a

@ -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
}

@ -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)
}

Loading…
Cancel
Save