ax(mining): replace prose comments with usage examples in repository.go
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:
parent
ac21008585
commit
ab4c764f3f
1 changed files with 4 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue