From 91a0ef4cb11a54099c56033ce3da8750e90f2c59 Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Sun, 18 Oct 2026 17:42:00 +0200 Subject: feat: use suture supervisor Replace the adhoc errgroup-based manager with the suture supervisor. Simply the HTTP server due to suture's service restart logic. --- main.go | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 0a5dac5..5d64e8d 100644 --- a/main.go +++ b/main.go @@ -16,9 +16,10 @@ import ( "time" "github.com/gorilla/mux" + "github.com/thejerf/suture/v4" + "github.com/thejerf/sutureslog" "go.terinstock.com/cgit-httpd/handlers/cgit" "go.terinstock.com/cgit-httpd/handlers/git" - "go.terinstock.com/cgit-httpd/manager" "go.terinstock.com/cgit-httpd/server" ) @@ -60,15 +61,20 @@ func main() { WithRegister(RegistererFunc(gitMux.Handle)). Build() - m := manager.New() - m.Add(&server.Server{ - Name: "git", - Server: &http.Server{ - Addr: net.JoinHostPort(cfg.HTTP.Host, strconv.Itoa(cfg.HTTP.Port)), - Handler: gitMux, - MaxHeaderBytes: 1 << 20, - IdleTimeout: 90 * time.Second, - ReadHeaderTimeout: 32 * time.Second, + supervisor := suture.New("cgit-httpd", + suture.Spec{ + EventHook: (&sutureslog.Handler{Logger: logger}).MustHook(), + }) + + supervisor.Add(&server.HTTPServer{ + NewServer: func() *http.Server { + return &http.Server{ + Addr: net.JoinHostPort(cfg.HTTP.Host, strconv.Itoa(cfg.HTTP.Port)), + Handler: gitMux, + MaxHeaderBytes: 1 << 20, + IdleTimeout: 90 * time.Second, + ReadHeaderTimeout: 32 * time.Second, + } }, }) @@ -81,20 +87,19 @@ func main() { mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) mux.HandleFunc("/debug/pprof/trace", pprof.Trace) - m.Add(&server.Server{ - Name: "pprof", - Server: &http.Server{ - Addr: net.JoinHostPort(cfg.Pprof.Host, strconv.Itoa(cfg.Pprof.Port)), - Handler: mux, + supervisor.Add(&server.HTTPServer{ + NewServer: func() *http.Server { + return &http.Server{ + Addr: net.JoinHostPort(cfg.Pprof.Host, strconv.Itoa(cfg.Pprof.Port)), + Handler: mux, + } }, }) } ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() - if err := m.Start(ctx); err != nil { - logger.Info("manager stopped", "error", err) - } + supervisor.Serve(ctx) } type RegistererFunc func(string, http.Handler) *mux.Route -- cgit v1.3