Documentation
¶
Overview ¶
Package shutdown provides graceful shutdown mechanisms for high availability.
Index ¶
- func Init(config Config)
- func IsShuttingDown() bool
- func Register(name string, priority int, fn func(ctx context.Context) error)
- func RegisterFunc(name string, fn func(ctx context.Context) error)
- func Shutdown()
- func Wait()
- type Callback
- type Config
- type Handler
- func (h *Handler) Done() <-chan struct{}
- func (h *Handler) IsShuttingDown() bool
- func (h *Handler) Register(name string, priority int, fn func(ctx context.Context) error)
- func (h *Handler) RegisterFunc(name string, fn func(ctx context.Context) error)
- func (h *Handler) Shutdown()
- func (h *Handler) Wait()
- func (h *Handler) WaitWithContext(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsShuttingDown ¶
func IsShuttingDown() bool
IsShuttingDown returns true if the global handler is shutting down.
func RegisterFunc ¶
RegisterFunc registers a callback with default priority using the global handler.
Types ¶
type Callback ¶
type Callback struct {
Name string
Priority int // Lower numbers run first
Func func(ctx context.Context) error
}
Callback represents a shutdown callback.
type Config ¶
type Config struct {
// Timeout is the maximum time to wait for shutdown.
// Default: 30 seconds
Timeout time.Duration
// Signals to listen for shutdown.
// Default: SIGINT, SIGTERM
Signals []os.Signal
}
Config holds shutdown handler configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages graceful shutdown.
func NewHandler ¶
NewHandler creates a new shutdown handler.
func (*Handler) Done ¶
func (h *Handler) Done() <-chan struct{}
Done returns a channel that's closed when shutdown is complete.
func (*Handler) IsShuttingDown ¶
IsShuttingDown returns true if shutdown has been initiated.
func (*Handler) Register ¶
Register registers a shutdown callback. Lower priority numbers are executed first.
func (*Handler) RegisterFunc ¶
RegisterFunc registers a shutdown callback with default priority (100).