shutdown

package
v1.21.55 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	PriorityIngress  = 0
	PriorityDefault  = 100
	PriorityWorkers  = 200
	PriorityDatabase = 300
	PriorityCritical = 400
)

Variables

This section is empty.

Functions

func AddHook

func AddHook(label string, fn func())

AddHook registers a shutdown hook with default priority

func AddHookWithPriority

func AddHookWithPriority(label string, priority int, fn func())

AddHookWithPriority registers a shutdown hook with specific priority

func RecoverAndShutdown

func RecoverAndShutdown()

RecoverAndShutdown is intended to be deferred in main(). On panic it runs all shutdown hooks and restores terminal state, then re-panics so the stack trace is preserved.

func RunAndWait

func RunAndWait(fn func() error) error

RunAndWait runs the provided function and then waits for shutdown signal

func SetTerminalRestoreFunc

func SetTerminalRestoreFunc(fn func())

SetTerminalRestoreFunc registers a callback that performs full terminal state restoration (e.g. term.Restore with saved state). Called automatically during Shutdown, force-exit, and RecoverAndShutdown.

func SetTerminalWriter added in v1.21.55

func SetTerminalWriter(w io.Writer)

SetTerminalWriter points the terminal reset at the writer that owns the terminal, so the sequence serializes with everything else clicky prints there. It must be a writer that reaches the terminal synchronously: the reset is terminal control, not log output, and a writer that defers or drops it leaves the cursor hidden after exit. Defaults to os.Stderr — the writer this package can reach without depending on the renderer that sits above it.

func Shutdown

func Shutdown()

Shutdown executes all registered hooks in priority order

func WaitForSignal

func WaitForSignal()

WaitForSignal waits for interrupt signals and triggers shutdown

Types

type Hook

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

type HookHeap

type HookHeap []*Hook

func (HookHeap) Len

func (h HookHeap) Len() int

func (HookHeap) Less

func (h HookHeap) Less(i, j int) bool

func (*HookHeap) Pop

func (h *HookHeap) Pop() interface{}

func (*HookHeap) Push

func (h *HookHeap) Push(x interface{})

func (HookHeap) Swap

func (h HookHeap) Swap(i, j int)

Jump to

Keyboard shortcuts

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