shutdown

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package shutdown provides graceful shutdown mechanisms for high availability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(config Config)

Init initializes the global shutdown handler.

func IsShuttingDown

func IsShuttingDown() bool

IsShuttingDown returns true if the global handler is shutting down.

func Register

func Register(name string, priority int, fn func(ctx context.Context) error)

Register registers a callback with the global handler.

func RegisterFunc

func RegisterFunc(name string, fn func(ctx context.Context) error)

RegisterFunc registers a callback with default priority using the global handler.

func Shutdown

func Shutdown()

Shutdown initiates shutdown using the global handler.

func Wait

func Wait()

Wait blocks until shutdown 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

func NewHandler(config Config) *Handler

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

func (h *Handler) IsShuttingDown() bool

IsShuttingDown returns true if shutdown has been initiated.

func (*Handler) Register

func (h *Handler) Register(name string, priority int, fn func(ctx context.Context) error)

Register registers a shutdown callback. Lower priority numbers are executed first.

func (*Handler) RegisterFunc

func (h *Handler) RegisterFunc(name string, fn func(ctx context.Context) error)

RegisterFunc registers a shutdown callback with default priority (100).

func (*Handler) Shutdown

func (h *Handler) Shutdown()

Shutdown initiates graceful shutdown.

func (*Handler) Wait

func (h *Handler) Wait()

Wait blocks until a shutdown signal is received and all callbacks complete.

func (*Handler) WaitWithContext

func (h *Handler) WaitWithContext(ctx context.Context) error

WaitWithContext blocks until shutdown or context cancellation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL