Documentation
¶
Overview ¶
Package storage manages the on-disk data layout (container for the FingerGo app data).
Directory structure created by Init():
{root}/
├── texts/
│ ├── index.json # metadata: categories, text entries
│ └── content/
│ └── {id}.txt # actual text content by ID
├── sessions.json # typing session history
└── settings.json # user preferences
On first run, embedded defaults are copied to {root}/. Existing files are never overwritten (idempotent).
Index ¶
- Variables
- func DefaultRoot() string
- type Manager
- type SessionRepository
- type SettingsRepository
- type TextRepository
- func (r *TextRepository) DefaultText() (domain.Text, error)
- func (r *TextRepository) DeleteCategory(id string) error
- func (r *TextRepository) DeleteText(id string) error
- func (r *TextRepository) Library() (domain.TextLibrary, error)
- func (r *TextRepository) SaveCategory(cat *domain.Category) error
- func (r *TextRepository) SaveText(text *domain.Text) error
- func (r *TextRepository) Text(id string) (domain.Text, error)
- func (r *TextRepository) UpdateText(text *domain.Text) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrTextNotFound = errors.New("storage: text not found") ErrTextExists = errors.New("storage: text already exists") ErrEmptyTextID = errors.New("storage: text id is empty") ErrInvalidTextID = errors.New("storage: text id contains invalid characters") ErrEmptyTextTitle = errors.New("storage: text title is empty") ErrTextTitleTooLong = errors.New("storage: text title too long") ErrEmptyTextContent = errors.New("storage: text content is empty") ErrTextContentTooLarge = errors.New("storage: text content too large") ErrInvalidLanguage = errors.New("storage: invalid language") )
Text validation errors.
var ( ErrCategoryExists = errors.New("storage: category already exists") ErrCategoryNotFound = errors.New("storage: category not found") ErrEmptyCategoryID = errors.New("storage: category id is empty") ErrInvalidCategoryID = errors.New("storage: category id contains invalid characters") ErrEmptyCategoryName = errors.New("storage: category name is empty") ErrCategoryNameTooLong = errors.New("storage: category name too long") )
Category validation errors.
Functions ¶
func DefaultRoot ¶
func DefaultRoot() string
DefaultRoot returns platform-specific application data directory. - Linux: $XDG_DATA_HOME/FingerGo or ~/.local/share/FingerGo - macOS: ~/Library/Application Support/FingerGo - Windows: %APPDATA%\FingerGo (e.g., C:\Users\Name\AppData\Roaming\FingerGo)
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the on-disk data layout for FingerGo.
func (*Manager) Init ¶
Init ensures the expected directory structure exists and seeds fallback data. Safe to call multiple times — existing files are not overwritten.
Creates:
- {root}/texts/
- {root}/texts/content/
- {root}/texts/index.json (from embedded)
- {root}/texts/content/{id}.txt (from embedded)
- {root}/sessions.json (empty array)
type SessionRepository ¶
type SessionRepository struct {
// contains filtered or unexported fields
}
SessionRepository persists typing sessions in sessions.json.
func NewSessionRepository ¶
func NewSessionRepository(mgr *Manager) (*SessionRepository, error)
NewSessionRepository wires the repository to the storage manager.
func (*SessionRepository) List ¶
func (r *SessionRepository) List(limit int) ([]domain.TypingSession, error)
List returns recent sessions (newest first). limit <= 0 returns all.
func (*SessionRepository) Record ¶
func (r *SessionRepository) Record(payload *domain.SessionPayload) (domain.TypingSession, error)
Record persists a session payload and returns the stored session.
type SettingsRepository ¶
type SettingsRepository struct {
// contains filtered or unexported fields
}
SettingsRepository persists user settings in settings.json.
func NewSettingsRepository ¶
func NewSettingsRepository(mgr *Manager) (*SettingsRepository, error)
NewSettingsRepository wires the repository to the storage manager.
func (*SettingsRepository) Load ¶
func (r *SettingsRepository) Load() (domain.Settings, error)
Load returns current settings, loading from disk on first access.
type TextRepository ¶
type TextRepository struct {
// contains filtered or unexported fields
}
TextRepository manages the text library with lazy loading and caching.
Design:
- Metadata (index.json) loaded once on first access
- Content files loaded on demand and cached in memory
- All public methods are thread-safe (guarded by RWMutex)
- Writes persist both in-memory state and disk atomically
- O(1) lookups via textIndex and sliceIndex maps
func NewTextRepository ¶
func NewTextRepository(mgr *Manager) (*TextRepository, error)
NewTextRepository wires repository to the storage manager.
func (*TextRepository) DefaultText ¶
func (r *TextRepository) DefaultText() (domain.Text, error)
DefaultText resolves and returns the configured default text with content.
func (*TextRepository) DeleteCategory ¶
func (r *TextRepository) DeleteCategory(id string) error
DeleteCategory removes a category entry by ID and all texts belonging to it. Returns ErrCategoryNotFound if category doesn't exist.
func (*TextRepository) DeleteText ¶
func (r *TextRepository) DeleteText(id string) error
DeleteText removes a text entry by ID.
func (*TextRepository) Library ¶
func (r *TextRepository) Library() (domain.TextLibrary, error)
Library returns metadata for texts and categories (content stripped).
func (*TextRepository) SaveCategory ¶
func (r *TextRepository) SaveCategory(cat *domain.Category) error
SaveCategory creates a new category entry. Returns ErrCategoryExists if a category with the same ID or name already exists.
func (*TextRepository) SaveText ¶
func (r *TextRepository) SaveText(text *domain.Text) error
SaveText creates a new text entry with content. Returns ErrTextExists if a text with the same ID already exists.
func (*TextRepository) Text ¶
func (r *TextRepository) Text(id string) (domain.Text, error)
Text returns a text (metadata + content) by identifier.
func (*TextRepository) UpdateText ¶
func (r *TextRepository) UpdateText(text *domain.Text) error
UpdateText modifies an existing text entry.