ax(mining): replace prose comments with usage examples in profile_manager.go
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 <charon@lethean.io>
This commit is contained in:
parent
6555e1211c
commit
aa9f0dd707
1 changed files with 12 additions and 7 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue