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) var log_info = log.New(os.Stdout, "", 0)
func bail(status int, t string, args ...interface{}) { func bail(status int, t string, args ...interface{}) {
if status != nil { if status != 0 {
shutdown(fmt.Errorf(t, args...)) shutdown(fmt.Errorf(t, args...))
} else { } else {
log_info.Printf log_info.Printf(t, args...)
} shutdown(nil)
out := log_info
if status != 0 {
out = log_error
} }
out.Printf(t+"\n", args...)
shutdown(status)
} }
//go:embed usage //go:embed usage
@ -46,12 +41,12 @@ func run(o options) error {
if err != nil { if err != nil {
return fmt.Errorf("unable to open unix socket: %w", err) return fmt.Errorf("unable to open unix socket: %w", err)
} }
onShutdown(func() { l.Close() }) onShutdown(func() error { return l.Close() })
server := http.Server{ server := http.Server{
Handler: new(handler), Handler: new(handler),
} }
onShutdown(func() { server.Shutdown(nil) }) onShutdown(func() error { return server.Shutdown(nil) })
// ?? // ??
start := time.Now() start := time.Now()
@ -71,10 +66,10 @@ func sigCancel(ctx context.Context) context.Context {
signal.Notify(c, os.Interrupt) signal.Notify(c, os.Interrupt)
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
onShutdown(cancel) onShutdown(func() error { cancel(); return nil })
go func() { go func() {
<-c <-c
shutdown() shutdown(nil)
}() }()
return ctx return ctx
} }

@ -2,9 +2,10 @@ package main
import ( import (
"sync" "sync"
"os"
) )
var shutdownHandlers []func() var shutdownHandlers []func() error
var shutdownOnce sync.Once var shutdownOnce sync.Once
func shutdown(cause error) { 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) shutdownHandlers = append(shutdownHandlers, f)
} }

Loading…
Cancel
Save