shutdown

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package shutdown provides graceful shutdown handling for the DAST crawler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, callback ShutdownCallback)

Register registers a callback with the global handler.

func RegisterFunc

func RegisterFunc(name string, fn func())

RegisterFunc registers a function with the global handler.

func SetGlobal

func SetGlobal(h *Handler)

SetGlobal sets the global shutdown handler.

func Shutdown

func Shutdown()

Shutdown triggers shutdown on the global handler.

Types

type Config

type Config struct {
	Timeout         time.Duration
	Signals         []os.Signal
	OnShutdownStart func()
	OnShutdownDone  func(elapsed time.Duration, errors []error)
}

Config holds shutdown configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default configuration.

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator coordinates multiple shutdown handlers.

func NewCoordinator

func NewCoordinator() *Coordinator

NewCoordinator creates a new coordinator.

func (*Coordinator) Add

func (c *Coordinator) Add(h *Handler)

Add adds a handler to the coordinator.

func (*Coordinator) ShutdownAll

func (c *Coordinator) ShutdownAll()

ShutdownAll triggers shutdown on all handlers.

func (*Coordinator) WaitAll

func (c *Coordinator) WaitAll()

WaitAll waits for all handlers to complete shutdown.

type GracefulServer

type GracefulServer interface {
	Shutdown(ctx context.Context) error
}

GracefulServer wraps a component that needs graceful shutdown.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler manages graceful shutdown.

func Global

func Global() *Handler

Global returns the global shutdown handler.

func New

func New(cfg Config) *Handler

New creates a new shutdown handler.

func NewDefault

func NewDefault() *Handler

NewDefault creates a handler with default configuration.

func (*Handler) Context

func (h *Handler) Context() context.Context

Context returns the shutdown context. This context is cancelled when shutdown begins.

func (*Handler) Done

func (h *Handler) Done() <-chan struct{}

Done returns a channel that is closed when shutdown completes.

func (*Handler) IsShuttingDown

func (h *Handler) IsShuttingDown() bool

IsShuttingDown returns whether shutdown is in progress.

func (*Handler) ListenAndShutdown

func (h *Handler) ListenAndShutdown() <-chan struct{}

ListenAndShutdown starts listening for signals and handles shutdown. Returns a channel that receives when shutdown is complete.

func (*Handler) Register

func (h *Handler) Register(name string, callback ShutdownCallback)

Register registers a shutdown callback with a name.

func (*Handler) RegisterFunc

func (h *Handler) RegisterFunc(name string, fn func())

RegisterFunc registers a simple cleanup function.

func (*Handler) RegisterServer

func (h *Handler) RegisterServer(name string, server GracefulServer)

RegisterServer registers a GracefulServer for shutdown.

func (*Handler) Shutdown

func (h *Handler) Shutdown()

Shutdown initiates graceful shutdown.

func (*Handler) ShutdownNow

func (h *Handler) ShutdownNow()

ShutdownNow initiates immediate shutdown without waiting for callbacks.

func (*Handler) Trigger

func (h *Handler) Trigger()

Trigger manually triggers shutdown (for testing or programmatic shutdown).

func (*Handler) Wait

func (h *Handler) Wait()

Wait blocks until a shutdown signal is received.

func (*Handler) WaitWithContext

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

WaitWithContext waits for shutdown or context cancellation.

type ShutdownCallback

type ShutdownCallback func(ctx context.Context) error

ShutdownCallback is a function called during shutdown.

type ShutdownResult

type ShutdownResult struct {
	Elapsed time.Duration
	Errors  []error
}

ShutdownResult holds the result of a shutdown operation.

func (*ShutdownResult) HasErrors

func (r *ShutdownResult) HasErrors() bool

HasErrors returns whether any errors occurred during shutdown.

type TimeoutError

type TimeoutError struct {
	CallbackName string
}

TimeoutError is returned when a callback times out.

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

Jump to

Keyboard shortcuts

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