diff options
| author | 2026-10-18 17:42:00 +0200 | |
|---|---|---|
| committer | 2026-10-18 18:19:51 +0200 | |
| commit | 91a0ef4cb11a54099c56033ce3da8750e90f2c59 (patch) | |
| tree | 452b7fe050fa000ab0ad2baebc7738db7d5d84f3 /main.go | |
| parent | chore: change license to EUPL-1.2 (diff) | |
| download | cgit-httpd-0.6.0.tar.xz | |
feat: use suture supervisorv0.6.0
Replace the adhoc errgroup-based manager with the suture supervisor.
Simply the HTTP server due to suture's service restart logic.
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 41 |
1 files changed, 23 insertions, 18 deletions
@@ -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 |
