ubgo is in early alpha: libraries and APIs may still change.

Skip to content
ubgo Alpha

shutdown

Phased graceful shutdown for services, parallel within a phase, with a watchdog and telemetry hooks.

go get github.com/ubgo/shutdown
Language
Go
Go version
1.24
Core deps
0 direct
Latest tag
v0.2.0
License
Apache-2.0
Go modules
9

How it fits together

Code from the README

mgr := shutdown.New(shutdown.WithBudget(30 * time.Second))

srv := &http.Server{Addr: ":8080", Handler: r}
_ = shutdownnethttp.Register(mgr, srv)

_ = mgr.Register("db",    closeFn(db.Close),  shutdown.WithPhase(shutdown.PhaseCloseClients))
_ = mgr.Register("redis", closeFn(rdb.Close), shutdown.WithPhase(shutdown.PhaseCloseClients))

go func() { _ = srv.ListenAndServe() }()
_ = mgr.Listen(ctx)

From the shutdown README.

At a glance (from the README)

AdapterModule pathRole
shutdown-nethttpgithub.com/ubgo/shutdown/contrib/shutdown-nethttp*http.Server.Shutdown registered as a phase handler
shutdown-gingithub.com/ubgo/shutdown/contrib/shutdown-ginSame, for the *http.Server wrapping a Gin engine
shutdown-chigithub.com/ubgo/shutdown/contrib/shutdown-chiSame, for the *http.Server wrapping a Chi router
shutdown-echogithub.com/ubgo/shutdown/contrib/shutdown-echo*echo.Echo.Shutdown (Echo owns its server)
shutdown-fibergithub.com/ubgo/shutdown/contrib/shutdown-fiber*fiber.App.ShutdownWithContext
shutdown-zapgithub.com/ubgo/shutdown/contrib/shutdown-zapObserver that emits structured logs via go.uber.org/zap
shutdown-otelgithub.com/ubgo/shutdown/contrib/shutdown-otelObserver that emits OpenTelemetry spans (root + phase + handler)
shutdown-promgithub.com/ubgo/shutdown/contrib/shutdown-promObserver that exports Prometheus metrics