kvstore

package
v0.1.40 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KVRecord

type KVRecord struct {
	Key       string `db:"key"`
	Value     string `db:"value"`
	UpdatedAt string `db:"updated_at"`
}

KVRecord represents a key-value record in the database

type KVStore

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

KVStore provides a key-value configuration store with caching

func NewKVStore

func NewKVStore(db *sqlx.DB) *KVStore

NewKVStore creates a new KV store instance

func (*KVStore) Delete

func (kv *KVStore) Delete(key Key) error

Delete removes a string key-value pair from database and string cache only

func (*KVStore) DeleteInt

func (kv *KVStore) DeleteInt(key KeyInt) error

DeleteInt removes an integer key-value pair from database and int cache only

func (*KVStore) DeleteRaw

func (kv *KVStore) DeleteRaw(keyStr string) error

DeleteRaw removes a key-value pair by raw key string

func (*KVStore) EnsureSystemDefaults

func (kv *KVStore) EnsureSystemDefaults() error

EnsureSystemDefaults ensures all required system parameters exist with sensible defaults This should be called during Initialize() to populate missing system parameters

func (*KVStore) ExistsRaw

func (kv *KVStore) ExistsRaw(keyStr string) bool

ExistsRaw checks if a raw key string exists in the store

func (*KVStore) Get

func (kv *KVStore) Get(key Key) (string, error)

Get retrieves a string value by key, checking string cache only

func (*KVStore) GetAll

func (kv *KVStore) GetAll() ([]*KVRecord, error)

GetAll retrieves all key-value pairs from the database using sqlx Select

func (*KVStore) GetDisplayName

func (kv *KVStore) GetDisplayName() string

GetDisplayName returns the system display name or hostname if empty

func (*KVStore) GetInt

func (kv *KVStore) GetInt(key KeyInt) (int, error)

GetInt retrieves an integer value by key, using integer cache only

func (*KVStore) GetIntWithDefault

func (kv *KVStore) GetIntWithDefault(key KeyInt, defaultValue int) int

GetIntWithDefault retrieves an integer value by key, returning default if not found

func (*KVStore) GetRaw

func (kv *KVStore) GetRaw(keyStr string) (string, error)

GetRaw retrieves a value by raw key string from appropriate cache or database

func (*KVStore) GetWithDefault

func (kv *KVStore) GetWithDefault(key Key, defaultValue string) string

GetWithDefault retrieves a value by key, returning default if not found

func (*KVStore) Initialize

func (kv *KVStore) Initialize() error

Initialize loads the initial cache from database and sets up system defaults This should be called after database migrations are complete

func (*KVStore) RequiredInt

func (kv *KVStore) RequiredInt(key KeyInt) int

RequiredInt returns the value of a required integer system parameter. Parameters are seeded by EnsureSystemDefaults, so a miss means the kvstore row was deleted or corrupted; rather than crashing the daemon (this is called from long-running paths like health checks), it logs loudly and falls back to the registered default.

func (*KVStore) Set

func (kv *KVStore) Set(key Key, value string) error

Set stores a string key-value pair, updating database and string cache only

func (*KVStore) SetInt

func (kv *KVStore) SetInt(key KeyInt, value int) error

SetInt stores an integer key-value pair, updating database and int cache only

func (*KVStore) SetRaw

func (kv *KVStore) SetRaw(keyStr, value string) error

SetRaw stores a value by raw key string in appropriate cache and database

type Key

type Key string

Key represents a strongly-typed configuration key for string values

const (
	// System display name (empty = use hostname)
	KeySystemDisplayName Key = "system.display.name.str"
)

String configuration keys - users must use these constants

func (Key) String

func (k Key) String() string

String returns the string representation of the key

type KeyInt

type KeyInt string

KeyInt represents a strongly-typed configuration key for integer values

const (
	// Health check thresholds
	KeyHealthDegradedThreshold KeyInt = "health.degraded_threshold.int"
	KeyHealthRestoredThreshold KeyInt = "health.restored_threshold.int"

	// Disk space thresholds
	KeyDiskSpaceThresholdBytes KeyInt = "health.disk_space_threshold_bytes.int"

	// CPU load thresholds (stored as percentage 0-100)
	KeyCPULoadThresholdPercent KeyInt = "health.cpu_load_threshold_percent.int"

	// Health check intervals
	KeyHealthCheckIntervalSec KeyInt = "health.check_interval_sec.int"

	// Debug settings
	KeyHealthDebugFail KeyInt = "health.debug_fail.int" // When non-zero, forces health checks to fail

	// Cron debug settings
	KeyCronDebugTickerInterval KeyInt = "cron.debug_ticker_interval.int" // Override cron ticker interval in seconds (0 = use default 60s)
	KeyCronDebugForceRun       KeyInt = "cron.debug_force_run.int"       // When 1, get all plans and force probability to 1.0

	// Backup debug settings
	KeyBackupDebugTimeMachine KeyInt = "backup.debug_time_machine.int" // When 1, enables debug endpoint to time-shift backups
)

Integer configuration keys - users must use these constants

func (KeyInt) String

func (k KeyInt) String() string

String returns the string representation of the integer key

Jump to

Keyboard shortcuts

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