Documentation
¶
Overview ¶
Package storage defines the interface for data persistence.
Index ¶
- func GetDefaultDBPath() (string, error)
- type ErrDeviceExists
- type JSONStore
- func (js *JSONStore) AddDevice(newDevice models.Device) error
- func (js *JSONStore) GetAllDevices() ([]models.Device, error)
- func (js *JSONStore) GetDeviceByHost(host string) (*models.Device, error)
- func (js *JSONStore) RemoveDevice(host string) error
- func (js *JSONStore) UpdateDevice(updatedDevice models.Device) error
- type SQLiteStore
- func (s *SQLiteStore) AddDevice(dev models.Device) error
- func (s *SQLiteStore) GetAllDevices() ([]models.Device, error)
- func (s *SQLiteStore) GetDeviceByHost(host string) (*models.Device, error)
- func (s *SQLiteStore) RemoveDevice(host string) error
- func (s *SQLiteStore) UpdateDevice(dev models.Device) error
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultDBPath ¶
GetDefaultDBPath returns the default path for the SQLite database file. It ensures the parent directory exists. Path: ~/.config/netcfg-backup/netcfg.db
Types ¶
type ErrDeviceExists ¶
type ErrDeviceExists struct {
Host string
}
ErrDeviceExists is a custom error type for duplicate devices.
func (*ErrDeviceExists) Error ¶
func (e *ErrDeviceExists) Error() string
type JSONStore ¶
type JSONStore struct {
// contains filtered or unexported fields
}
JSONStore implements the Store interface using a JSON file.
func NewJSONStore ¶
NewJSONStore creates a new instance of a JSONStore.
func (*JSONStore) AddDevice ¶
AddDevice adds a new device to the JSON file. It reads the existing devices, appends the new one, and writes the file back.
func (*JSONStore) GetAllDevices ¶
GetAllDevices reads and parses the device list from the JSON file.
func (*JSONStore) GetDeviceByHost ¶
GetDeviceByHost finds a single device by its host.
func (*JSONStore) RemoveDevice ¶
RemoveDevice removes a device from the JSON file by its host.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore implements the Store interface using a SQLite database.
func NewSQLiteStore ¶
func NewSQLiteStore(filePath string) (*SQLiteStore, error)
NewSQLiteStore creates a new SQLiteStore and ensures the database schema is set up.
func (*SQLiteStore) AddDevice ¶
func (s *SQLiteStore) AddDevice(dev models.Device) error
AddDevice adds a new device to the database.
func (*SQLiteStore) GetAllDevices ¶
func (s *SQLiteStore) GetAllDevices() ([]models.Device, error)
GetAllDevices retrieves all devices from the database.
func (*SQLiteStore) GetDeviceByHost ¶
func (s *SQLiteStore) GetDeviceByHost(host string) (*models.Device, error)
GetDeviceByHost finds a single device by its host.
func (*SQLiteStore) RemoveDevice ¶
func (s *SQLiteStore) RemoveDevice(host string) error
RemoveDevice removes a device from the database by its host.
func (*SQLiteStore) UpdateDevice ¶
func (s *SQLiteStore) UpdateDevice(dev models.Device) error
UpdateDevice updates an existing device in the database.
type Store ¶
type Store interface {
GetAllDevices() ([]models.Device, error)
GetDeviceByHost(host string) (*models.Device, error)
AddDevice(device models.Device) error
UpdateDevice(updatedDevice models.Device) error
RemoveDevice(host string) error
}
Store is the interface for device storage. It abstracts the underlying storage mechanism (e.g., JSON file, database).