Documentation
¶
Overview ¶
Package storage provides data persistence abstractions including file storage, key-value storage (Badger), and structured object storage (BadgerHold).
Index ¶
- type BadgerHoldStorage
- type BadgerStorage
- func (s *BadgerStorage) Delete(rowKey []byte) (err error)
- func (s *BadgerStorage) Do(processor func(db *badger.DB))
- func (s *BadgerStorage) Read(key Key, data Data) (err error)
- func (s *BadgerStorage) ReadAll(processor func(raw []byte) (err error)) (err error)
- func (s *BadgerStorage) ReadAllKey(processor func(key, raw []byte) (err error)) (err error)
- func (s *BadgerStorage) Save(value Data) (err error)
- type BadgerStorageReplicated
- type BinFileStorage
- type BinStorage
- type Data
- type Key
- type Manager
- func (m *Manager) GetBinFileStorage(name, moduleDbPath, moduleDbName string) (s BinStorage, err error)
- func (m *Manager) GetModuleStorage(name, dbPath string) (s *ModuleManager)
- func (m *Manager) GetNewBadgerHoldStorage(name, moduleDbPath, moduleDbName string) (s *BadgerHoldStorage, err error)
- func (m *Manager) GetNewBadgerStorage(name, moduleDbPath, moduleDbName string) (s SimpleKeyStorage, err error)
- type ModuleManager
- type Replicator
- type SimpleKeyStorage
- type SimpleStorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadgerHoldStorage ¶
type BadgerHoldStorage struct {
Name string `json:"-"` // Storage identifier
GlobalDbPath string `json:"-"` // Base data directory
DataPath string `json:"-"` // Module subdirectory
DataBaseName string `json:"-"` // Database directory name
// contains filtered or unexported fields
}
BadgerHoldStorage wraps BadgerHold for structured object storage. Supports auto-incrementing keys and ORM-like queries.
func NewBadgerHoldStorage ¶
func NewBadgerHoldStorage(name, globalDbPath, dbPath, dbFile string) (s *BadgerHoldStorage, err error)
NewBadgerHoldStorage creates a new BadgerHold storage instance. BadgerHold provides ORM-like functionality on top of Badger.
func (*BadgerHoldStorage) Do ¶
func (s *BadgerHoldStorage) Do(processor func(db *badgerhold.Store))
Do provides direct access to the underlying BadgerHold store. Use for advanced queries and operations.
func (*BadgerHoldStorage) Insert ¶
func (s *BadgerHoldStorage) Insert(value interface{}) (err error)
Insert adds a new record with an auto-incrementing key.
type BadgerStorage ¶
type BadgerStorage struct {
Name string `json:"-"` // Storage identifier
GlobalDbPath string `json:"-"` // Base data directory
DataPath string `json:"-"` // Module subdirectory
DataBaseName string `json:"-"` // Database directory name
// contains filtered or unexported fields
}
BadgerStorage implements SimpleKeyStorage using Badger embedded database. Provides high-performance key-value storage with ACID guarantees.
func NewBadgerStorage ¶
func NewBadgerStorage(name, globalDbPath, dbPath, dbFile string) (s *BadgerStorage, err error)
NewBadgerStorage creates a new Badger key-value database storage. Parameters:
- name: storage identifier for logging
- globalDbPath: base data directory
- dbPath: module-specific subdirectory
- dbFile: database directory name
func (*BadgerStorage) Delete ¶
func (s *BadgerStorage) Delete(rowKey []byte) (err error)
Delete removes a record by key from the database.
func (*BadgerStorage) Do ¶
func (s *BadgerStorage) Do(processor func(db *badger.DB))
Do provides direct access to the underlying Badger database. Use for advanced operations not covered by the interface.
func (*BadgerStorage) Read ¶
func (s *BadgerStorage) Read(key Key, data Data) (err error)
Read retrieves data by key and populates the data parameter. Returns badger.ErrKeyNotFound if the key doesn't exist.
func (*BadgerStorage) ReadAll ¶
func (s *BadgerStorage) ReadAll(processor func(raw []byte) (err error)) (err error)
ReadAll iterates over all records, calling processor for each value. Uses prefetch for efficient bulk reads.
func (*BadgerStorage) ReadAllKey ¶
func (s *BadgerStorage) ReadAllKey(processor func(key, raw []byte) (err error)) (err error)
ReadAllKey iterates over all records, calling processor with both key and value. Uses prefetch for efficient bulk reads.
func (*BadgerStorage) Save ¶
func (s *BadgerStorage) Save(value Data) (err error)
Save persists data to the database using the data's key.
type BadgerStorageReplicated ¶
type BadgerStorageReplicated struct {
BadgerStorage
// contains filtered or unexported fields
}
BadgerStorageReplicated extends BadgerStorage with replication support. All write operations are asynchronously replicated to the configured Replicator.
func NewBadgerStorageReplicated ¶
func NewBadgerStorageReplicated(name, globalDbPath, dbPath, dbFile string, replicator Replicator) (s *BadgerStorageReplicated, err error)
NewBadgerStorageReplicated creates a new Badger storage with replication support. All writes are asynchronously replicated via the provided Replicator.
func (*BadgerStorageReplicated) Delete ¶
func (s *BadgerStorageReplicated) Delete(rowKey []byte) (err error)
Delete removes a record and asynchronously replicates the deletion.
func (*BadgerStorageReplicated) Save ¶
func (s *BadgerStorageReplicated) Save(value Data) (err error)
Save persists data and asynchronously replicates the change.
type BinFileStorage ¶
type BinFileStorage struct {
Name string `json:"-"` // Storage identifier
GlobalDbPath string `json:"-"` // Base data directory
DataPath string `json:"-"` // Module subdirectory
DataBaseName string `json:"-"` // Filename
// contains filtered or unexported fields
}
BinFileStorage implements BinStorage using file system storage. Thread-safe for concurrent access.
func NewBinFileStorage ¶
func NewBinFileStorage(name, globalDbPath, dbPath, dbFile string) (s *BinFileStorage, err error)
NewBinFileStorage creates a new file-based binary storage. Parameters:
- name: storage identifier for logging
- globalDbPath: base data directory
- dbPath: module-specific subdirectory
- dbFile: filename
func (*BinFileStorage) IsExists ¶
func (s *BinFileStorage) IsExists() bool
IsExists returns true if the storage file exists on disk.
func (*BinFileStorage) Load ¶
func (s *BinFileStorage) Load() (rawData []byte, err error)
Load reads and returns the raw binary data from the storage file.
func (*BinFileStorage) Save ¶
func (s *BinFileStorage) Save(rawData []byte) (err error)
Save writes raw binary data to the storage file. Creates the directory structure if it doesn't exist.
type BinStorage ¶
type BinStorage interface {
// IsExists returns true if the storage file exists.
IsExists() bool
// Save writes raw binary data to storage.
Save(rawData []byte) (err error)
// Load reads raw binary data from storage.
Load() (rawData []byte, err error)
}
BinStorage defines an interface for binary file storage operations. Used for configuration files and other binary data.
type Data ¶
type Data interface {
Key
// Encode serializes the data to bytes for storage.
Encode() []byte
// Decode deserializes the data from bytes.
Decode([]byte) error
}
Data interface defines a type that can be stored and retrieved from storage. It extends Key and adds encoding/decoding capabilities.
type Key ¶
type Key interface {
// GetKey returns the byte representation of the storage key.
GetKey() []byte
}
Key interface defines a type that can provide its storage key.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the central storage manager that coordinates all storage backends. It provides thread-safe access to file storage, Badger KV, and BadgerHold databases.
func NewStorageManager ¶
NewStorageManager creates a new storage manager with the specified data directory. Creates the directory if it doesn't exist.
func (*Manager) GetBinFileStorage ¶
func (m *Manager) GetBinFileStorage(name, moduleDbPath, moduleDbName string) (s BinStorage, err error)
GetBinFileStorage creates and returns a file-based binary storage. Thread-safe operation.
func (*Manager) GetModuleStorage ¶
func (m *Manager) GetModuleStorage(name, dbPath string) (s *ModuleManager)
GetModuleStorage creates and returns a module-specific storage manager. Creates the module's storage directory if it doesn't exist.
func (*Manager) GetNewBadgerHoldStorage ¶
func (m *Manager) GetNewBadgerHoldStorage(name, moduleDbPath, moduleDbName string) (s *BadgerHoldStorage, err error)
GetNewBadgerHoldStorage creates and returns a new BadgerHold structured database. Thread-safe operation.
func (*Manager) GetNewBadgerStorage ¶
func (m *Manager) GetNewBadgerStorage(name, moduleDbPath, moduleDbName string) (s SimpleKeyStorage, err error)
GetNewBadgerStorage creates and returns a new Badger key-value database. Thread-safe operation.
type ModuleManager ¶
type ModuleManager struct {
// contains filtered or unexported fields
}
ModuleManager provides module-specific storage access. Each module (address, watchdog, etc.) gets its own isolated storage namespace.
func (*ModuleManager) GetBinFileStorage ¶
func (mm *ModuleManager) GetBinFileStorage(dbName string) (s BinStorage)
GetBinFileStorage returns a file-based binary storage for the module. The dbName is the filename within the module's storage directory.
func (*ModuleManager) GetNewBadgerHoldStorage ¶
func (mm *ModuleManager) GetNewBadgerHoldStorage(moduleDbName string) (s *BadgerHoldStorage)
GetNewBadgerHoldStorage returns a BadgerHold structured storage for the module. The moduleDbName is the database directory name within the module's storage.
func (*ModuleManager) GetNewBadgerStorage ¶
func (mm *ModuleManager) GetNewBadgerStorage(moduleDbName string) (s SimpleKeyStorage)
GetNewBadgerStorage returns a Badger key-value storage for the module. The moduleDbName is the database directory name within the module's storage.
type Replicator ¶
type Replicator interface {
// Update is called when data is saved.
Update(key []byte, data []byte)
// Delete is called when data is deleted.
Delete(key []byte)
}
Replicator defines an interface for asynchronous data replication.
type SimpleKeyStorage ¶
type SimpleKeyStorage interface {
// Save persists data to storage.
Save(data Data) (err error)
// Read retrieves data by key and populates the data parameter.
Read(key Key, data Data) (err error)
// ReadAll iterates over all records, calling processor for each value.
ReadAll(processor func(raw []byte) (err error)) (err error)
// ReadAllKey iterates over all records, calling processor with both key and value.
ReadAllKey(processor func(key, raw []byte) (err error)) (err error)
// Delete removes a record by key.
Delete(rowKey []byte) (err error)
}
SimpleKeyStorage extends SimpleStorage with key-aware iteration.
type SimpleStorage ¶
type SimpleStorage interface {
// Save persists data to storage.
Save(data Data) (err error)
// Read retrieves data by key and populates the data parameter.
Read(key Key, data Data) (err error)
// ReadAll iterates over all records, calling processor for each.
ReadAll(processor func(raw []byte) (err error)) (err error)
// Delete removes a record by key.
Delete(rowKey []byte) (err error)
}
SimpleStorage defines a basic key-value storage interface.