Documentation
¶
Index ¶
- Constants
- func AddHook(label string, fn func())
- func AddHookWithPriority(label string, priority int, fn func())
- func RecoverAndShutdown()
- func RunAndWait(fn func() error) error
- func SetTerminalRestoreFunc(fn func())
- func SetTerminalWriter(w io.Writer)
- func Shutdown()
- func WaitForSignal()
- type Hook
- type HookHeap
Constants ¶
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 ¶
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 ¶
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
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 WaitForSignal ¶
func WaitForSignal()
WaitForSignal waits for interrupt signals and triggers shutdown