storage

package
v0.0.0-...-177ba43 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package storage defines the interface for data persistence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultDBPath

func GetDefaultDBPath() (string, error)

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

func NewJSONStore(filePath string) *JSONStore

NewJSONStore creates a new instance of a JSONStore.

func (*JSONStore) AddDevice

func (js *JSONStore) AddDevice(newDevice models.Device) error

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

func (js *JSONStore) GetAllDevices() ([]models.Device, error)

GetAllDevices reads and parses the device list from the JSON file.

func (*JSONStore) GetDeviceByHost

func (js *JSONStore) GetDeviceByHost(host string) (*models.Device, error)

GetDeviceByHost finds a single device by its host.

func (*JSONStore) RemoveDevice

func (js *JSONStore) RemoveDevice(host string) error

RemoveDevice removes a device from the JSON file by its host.

func (*JSONStore) UpdateDevice

func (js *JSONStore) UpdateDevice(updatedDevice models.Device) error

UpdateDevice finds a device by its host and replaces it with the new version.

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).

Jump to

Keyboard shortcuts

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