ax(mining): replace prose comments with usage examples in repository.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Three comments violated AX Principle 2 (comments as usage examples):
- Repository interface comment described what it was rather than showing usage
- FileRepositoryOption comment said "configures a FileRepository" (restates the type)
- saveUnlocked comment described behaviour rather than showing the call pattern

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 17:13:36 +01:00
parent ac21008585
commit ab4c764f3f
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -7,8 +7,8 @@ import (
"sync"
)
// Repository defines a generic interface for data persistence.
// Implementations can store data in files, databases, etc.
// var repo Repository[MinersConfig] = NewFileRepository[MinersConfig](path)
// data, err := repo.Load()
type Repository[T any] interface {
// data, err := repo.Load()
Load() (T, error)
@ -28,7 +28,7 @@ type FileRepository[T any] struct {
defaults func() T
}
// FileRepositoryOption configures a FileRepository.
// repo := NewFileRepository[MinersConfig](path, WithDefaults(defaultMinersConfig), myOption)
type FileRepositoryOption[T any] func(*FileRepository[T])
// repo := NewFileRepository[MinersConfig](path, WithDefaults(defaultMinersConfig))
@ -83,7 +83,7 @@ func (r *FileRepository[T]) Save(data T) error {
return r.saveUnlocked(data)
}
// saveUnlocked saves data without acquiring the lock (caller must hold lock).
// r.mutex.Lock(); defer r.mutex.Unlock(); return r.saveUnlocked(data)
func (r *FileRepository[T]) saveUnlocked(data T) error {
dir := filepath.Dir(r.path)
if err := os.MkdirAll(dir, 0755); err != nil {