From aa9f0dd7074839fedbcf85ddd0974ce4f9b2480c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 08:12:59 +0100 Subject: [PATCH] ax(mining): replace prose comments with usage examples in profile_manager.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All public API comments on ProfileManager restated the type signature in prose — violating AX principle 2 (comments as usage examples). Replaced with concrete call examples showing realistic values. Co-Authored-By: Charon --- pkg/mining/profile_manager.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/mining/profile_manager.go b/pkg/mining/profile_manager.go index b7e33dd..03536ba 100644 --- a/pkg/mining/profile_manager.go +++ b/pkg/mining/profile_manager.go @@ -13,14 +13,16 @@ import ( const profileConfigFileName = "mining_profiles.json" -// ProfileManager handles CRUD operations for MiningProfiles. +// pm, err := NewProfileManager() +// pm.CreateProfile(profile) type ProfileManager struct { mu sync.RWMutex profiles map[string]*MiningProfile configPath string } -// NewProfileManager creates and initializes a new ProfileManager. +// pm, err := NewProfileManager() +// if err != nil { return err } func NewProfileManager() (*ProfileManager, error) { configPath, err := xdg.ConfigFile(filepath.Join("lethean-desktop", profileConfigFileName)) if err != nil { @@ -82,7 +84,7 @@ func (pm *ProfileManager) saveProfiles() error { return AtomicWriteFile(pm.configPath, data, 0600) } -// CreateProfile adds a new profile and saves it. +// created, err := pm.CreateProfile(&MiningProfile{Name: "XMRig CPU", MinerType: "xmrig"}) func (pm *ProfileManager) CreateProfile(profile *MiningProfile) (*MiningProfile, error) { pm.mu.Lock() defer pm.mu.Unlock() @@ -99,7 +101,8 @@ func (pm *ProfileManager) CreateProfile(profile *MiningProfile) (*MiningProfile, return profile, nil } -// GetProfile retrieves a profile by its ID. +// profile, ok := pm.GetProfile("abc-123") +// if !ok { return errors.New("profile not found") } func (pm *ProfileManager) GetProfile(id string) (*MiningProfile, bool) { pm.mu.RLock() defer pm.mu.RUnlock() @@ -107,7 +110,8 @@ func (pm *ProfileManager) GetProfile(id string) (*MiningProfile, bool) { return profile, exists } -// GetAllProfiles returns a list of all profiles. +// profiles := pm.GetAllProfiles() +// for _, p := range profiles { render(p) } func (pm *ProfileManager) GetAllProfiles() []*MiningProfile { pm.mu.RLock() defer pm.mu.RUnlock() @@ -119,7 +123,8 @@ func (pm *ProfileManager) GetAllProfiles() []*MiningProfile { return profileList } -// UpdateProfile modifies an existing profile. +// profile.Name = "XMRig GPU" +// if err := pm.UpdateProfile(profile); err != nil { return err } func (pm *ProfileManager) UpdateProfile(profile *MiningProfile) error { pm.mu.Lock() defer pm.mu.Unlock() @@ -142,7 +147,7 @@ func (pm *ProfileManager) UpdateProfile(profile *MiningProfile) error { return nil } -// DeleteProfile removes a profile by its ID. +// if err := pm.DeleteProfile("abc-123"); err != nil { return err } func (pm *ProfileManager) DeleteProfile(id string) error { pm.mu.Lock() defer pm.mu.Unlock()