lifecycle

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package lifecycle manages graceful shutdown with auto-save of session state, cache flush, and database closure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShredAll

func ShredAll(rlmDir string) []error

ShredAll shreds all known database files in the .rlm directory.

func ShredBoltDB

func ShredBoltDB(dbPath string) error

ShredBoltDB shreds a BoltDB database (4096-byte meta pages).

func ShredDatabase

func ShredDatabase(dbPath string, headerSize int) error

ShredDatabase irreversibly destroys a database file by overwriting its header with random bytes, making it unreadable without backup.

For SQLite: overwrites first 100 bytes (header with magic bytes "SQLite format 3\000"). For BoltDB: overwrites first 4096 bytes (two 4KB meta pages).

WARNING: This operation is IRREVERSIBLE. Data is only recoverable from peer backup.

func ShredSQLite

func ShredSQLite(dbPath string) error

ShredSQLite shreds a SQLite database (100-byte header).

Types

type Manager

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

Manager orchestrates graceful shutdown of all resources.

func NewManager

func NewManager(timeout time.Duration) *Manager

NewManager creates a new lifecycle Manager. Timeout is the maximum time allowed for all shutdown hooks to complete.

func (*Manager) Done

func (m *Manager) Done() bool

Done returns true if Shutdown has already been called.

func (*Manager) OnClose

func (m *Manager) OnClose(name string, c io.Closer)

OnClose registers an io.Closer as a shutdown hook.

func (*Manager) OnShutdown

func (m *Manager) OnShutdown(name string, fn func(ctx context.Context) error)

OnShutdown registers a shutdown hook. Hooks are called in LIFO order (last registered = first called), matching defer semantics.

func (*Manager) Shutdown

func (m *Manager) Shutdown() error

Shutdown executes all registered hooks in reverse order (LIFO). It logs each step and any errors. Returns the first error encountered.

type ShutdownFunc

type ShutdownFunc struct {
	Name string
	Fn   func(ctx context.Context) error
}

ShutdownFunc is a function called during graceful shutdown. Name is used for logging. The function receives a context with a deadline.

Jump to

Keyboard shortcuts

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