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()