ax(mining): replace pm abbreviation with profileManager in usage-example comments
AX Principle 1 (predictable names over short names): usage-example comments in profile_manager.go used the abbreviated `pm` receiver throughout, while all production code uses the full `profileManager` name. Comments are teaching material — agents and readers learn from them. Aligning examples with the actual variable name removes the abbreviation mapping overhead. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
68ee594149
commit
0fe74ae8a6
1 changed files with 12 additions and 12 deletions
|
|
@ -13,15 +13,15 @@ import (
|
|||
|
||||
const profileConfigFileName = "mining_profiles.json"
|
||||
|
||||
// pm, err := NewProfileManager()
|
||||
// pm.CreateProfile(profile)
|
||||
// profileManager, err := NewProfileManager()
|
||||
// profileManager.CreateProfile(profile)
|
||||
type ProfileManager struct {
|
||||
mutex sync.RWMutex
|
||||
profiles map[string]*MiningProfile
|
||||
configPath string
|
||||
}
|
||||
|
||||
// pm, err := NewProfileManager()
|
||||
// profileManager, err := NewProfileManager()
|
||||
// if err != nil { return err }
|
||||
func NewProfileManager() (*ProfileManager, error) {
|
||||
configPath, err := xdg.ConfigFile(filepath.Join("lethean-desktop", profileConfigFileName))
|
||||
|
|
@ -44,7 +44,7 @@ func NewProfileManager() (*ProfileManager, error) {
|
|||
return profileManager, nil
|
||||
}
|
||||
|
||||
// pm.loadProfiles() // call after acquiring pm.mutex.Lock() if needed externally
|
||||
// profileManager.loadProfiles() // call after acquiring profileManager.mutex.Lock() if needed externally
|
||||
func (profileManager *ProfileManager) loadProfiles() error {
|
||||
profileManager.mutex.Lock()
|
||||
defer profileManager.mutex.Unlock()
|
||||
|
|
@ -67,7 +67,7 @@ func (profileManager *ProfileManager) loadProfiles() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// pm.saveProfiles() // caller must hold pm.mutex before calling; uses atomic write (temp→sync→rename)
|
||||
// profileManager.saveProfiles() // caller must hold profileManager.mutex before calling; uses atomic write (temp→sync→rename)
|
||||
func (profileManager *ProfileManager) saveProfiles() error {
|
||||
profileList := make([]*MiningProfile, 0, len(profileManager.profiles))
|
||||
for _, profile := range profileManager.profiles {
|
||||
|
|
@ -82,7 +82,7 @@ func (profileManager *ProfileManager) saveProfiles() error {
|
|||
return AtomicWriteFile(profileManager.configPath, data, 0600)
|
||||
}
|
||||
|
||||
// created, err := pm.CreateProfile(&MiningProfile{Name: "XMRig CPU", MinerType: "xmrig"})
|
||||
// created, err := profileManager.CreateProfile(&MiningProfile{Name: "XMRig CPU", MinerType: "xmrig"})
|
||||
func (profileManager *ProfileManager) CreateProfile(profile *MiningProfile) (*MiningProfile, error) {
|
||||
profileManager.mutex.Lock()
|
||||
defer profileManager.mutex.Unlock()
|
||||
|
|
@ -99,8 +99,8 @@ func (profileManager *ProfileManager) CreateProfile(profile *MiningProfile) (*Mi
|
|||
return profile, nil
|
||||
}
|
||||
|
||||
// profile, ok := pm.GetProfile("abc-123")
|
||||
// if !ok { return errors.New("profile not found") }
|
||||
// profile, ok := profileManager.GetProfile("abc-123")
|
||||
// if !ok { return core.E("profile.Get", "profile not found", nil) }
|
||||
func (profileManager *ProfileManager) GetProfile(id string) (*MiningProfile, bool) {
|
||||
profileManager.mutex.RLock()
|
||||
defer profileManager.mutex.RUnlock()
|
||||
|
|
@ -108,8 +108,8 @@ func (profileManager *ProfileManager) GetProfile(id string) (*MiningProfile, boo
|
|||
return profile, exists
|
||||
}
|
||||
|
||||
// profiles := pm.GetAllProfiles()
|
||||
// for _, p := range profiles { render(p) }
|
||||
// profiles := profileManager.GetAllProfiles()
|
||||
// for _, profile := range profiles { render(profile) }
|
||||
func (profileManager *ProfileManager) GetAllProfiles() []*MiningProfile {
|
||||
profileManager.mutex.RLock()
|
||||
defer profileManager.mutex.RUnlock()
|
||||
|
|
@ -122,7 +122,7 @@ func (profileManager *ProfileManager) GetAllProfiles() []*MiningProfile {
|
|||
}
|
||||
|
||||
// profile.Name = "XMRig GPU"
|
||||
// if err := pm.UpdateProfile(profile); err != nil { return err }
|
||||
// if err := profileManager.UpdateProfile(profile); err != nil { return err }
|
||||
func (profileManager *ProfileManager) UpdateProfile(profile *MiningProfile) error {
|
||||
profileManager.mutex.Lock()
|
||||
defer profileManager.mutex.Unlock()
|
||||
|
|
@ -145,7 +145,7 @@ func (profileManager *ProfileManager) UpdateProfile(profile *MiningProfile) erro
|
|||
return nil
|
||||
}
|
||||
|
||||
// if err := pm.DeleteProfile("abc-123"); err != nil { return err }
|
||||
// if err := profileManager.DeleteProfile("abc-123"); err != nil { return err }
|
||||
func (profileManager *ProfileManager) DeleteProfile(id string) error {
|
||||
profileManager.mutex.Lock()
|
||||
defer profileManager.mutex.Unlock()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue