storage

package
v0.0.0-...-7dd612a Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderDate    = "Date"
	HeaderAmount  = "Amount"
	HeaderComment = "Comment"
	HeaderHabit   = "Habit"
	HeaderStatus  = "Status"
)
View Source
const DEFAULT_HABITS = `` /* 472-byte string literal not displayed */

Variables

View Source
var DefaultHeader = Header{
	HeaderDate:    0,
	HeaderHabit:   1,
	HeaderStatus:  2,
	HeaderComment: 3,
	HeaderAmount:  4,
}

Functions

func CreateExampleHabitsFile

func CreateExampleHabitsFile(configDir string)

CreateExampleHabitsFile writes a fresh Habits file for people to follow

func CreateNewLogFile

func CreateNewLogFile(configDir string)

CreateNewLogFile writes an empty log file for people to start tracking into

func FindConfigFiles

func FindConfigFiles() string

FindConfigFiles checks os relevant habits and log file exist, returns path If they do not exist, calls CreateExampleHabitsFile and CreateNewLogFile

func IsNotDigit

func IsNotDigit(r rune) bool

func WriteHabitLog

func WriteHabitLog(configDir string, d civil.Date, habit string, result string, comment string, amount string, header Header) error

WriteHabitLog writes the log entry for a habit to file

Types

type DailyHabit

type DailyHabit struct {
	Day   civil.Date
	Habit string
}

DailyHabit combines Day and Habit with an Outcome to yield Entries

type Entries

type Entries map[DailyHabit]Outcome

Entries maps DailyHabit{ISO date + habit}: Outcome and log format

func (*Entries) FirstRecords

func (e *Entries) FirstRecords(from civil.Date, to civil.Date, habits []*Habit)

FirstRecords sets the FirstRecord field for habits based on their earliest entries

type FileRepository

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

FileRepository implements Repository using file-based storage

func NewFileRepository

func NewFileRepository() *FileRepository

NewFileRepository creates a new file-based repository

func (*FileRepository) GetConfigDir

func (r *FileRepository) GetConfigDir() string

GetConfigDir returns the configuration directory

func (*FileRepository) InitializeConfig

func (r *FileRepository) InitializeConfig() error

InitializeConfig initializes the configuration if needed

func (*FileRepository) LoadEntries

func (r *FileRepository) LoadEntries() (*Log, error)

LoadEntries loads log entries from the log file

func (*FileRepository) LoadHabits

func (r *FileRepository) LoadHabits() ([]*Habit, int, error)

LoadHabits loads habits from the config file

func (*FileRepository) WriteEntry

func (r *FileRepository) WriteEntry(d civil.Date, habit string, result string, comment string, amount string, header Header) error

WriteEntry writes a log entry to the log file

type Habit

type Habit struct {
	Heading     string
	Name        string
	Frequency   string
	Target      int
	Interval    int
	FirstRecord civil.Date
}

Habit represents a habit with its configuration and tracking information

func LoadHabitsConfig

func LoadHabitsConfig(configDir string) ([]*Habit, int)

LoadHabitsConfig loads habits in config file ordered slice

func (*Habit) ParseHabitFrequency

func (habit *Habit) ParseHabitFrequency()

ParseHabitFrequency parses the frequency string and sets Target and Interval

type Header map[string]int

func ParseHeader

func ParseHeader(line string) (Header, error)

type Log

type Log struct {
	Entries Entries
	Header  Header
}

func LoadLog

func LoadLog(configDir string) *Log

LoadLog reads entries from log file

type Outcome

type Outcome struct {
	Result  string
	Amount  float64
	Comment string
}

Outcome is the explicit recorded result of a habit on a day (y, n, or s) and an optional amount and comment

type Repository

type Repository interface {
	// Habit operations
	LoadHabits() ([]*Habit, int, error)

	// Log operations
	LoadEntries() (*Log, error)
	WriteEntry(d civil.Date, habit string, result string, comment string, amount string, header Header) error

	// Configuration
	GetConfigDir() string
	InitializeConfig() error
}

Repository defines the interface for data access operations

Jump to

Keyboard shortcuts

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