summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2026-10-18 17:42:00 +0200
committerLibravatar Terin Stock <terinjokes@gmail.com>2026-10-18 18:19:51 +0200
commit91a0ef4cb11a54099c56033ce3da8750e90f2c59 (patch)
tree452b7fe050fa000ab0ad2baebc7738db7d5d84f3 /main.go
parentchore: change license to EUPL-1.2 (diff)
downloadcgit-httpd-25e09867a2b73acd07b9007a4c45e689c4041b19.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.go41
1 files changed, 23 insertions, 18 deletions
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