From ab4c764f3f883e836d40aae4c291530e7d8bbe63 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 17:13:36 +0100 Subject: [PATCH] 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 --- pkg/mining/repository.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/mining/repository.go b/pkg/mining/repository.go index 168482e..bb8bbd2 100644 --- a/pkg/mining/repository.go +++ b/pkg/mining/repository.go @@ -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 {