Skip to content

Commit

Permalink
refactor(preferences): ♻️ rename ID method for worker preferences
Browse files Browse the repository at this point in the history
- rename ID method to make it more clear what its purpose is
  • Loading branch information
joshuar committed Oct 30, 2024
1 parent b1b48db commit 9f44702
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/linux/net/linkSensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (w *AddressWorker) Events(ctx context.Context) (<-chan sensor.Entity, error
return sensorCh, nil
}

func (w *AddressWorker) ID() string {
func (w *AddressWorker) PreferencesID() string {
return preferencesID
}

Expand Down
2 changes: 1 addition & 1 deletion internal/linux/net/networkRates.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (w *netStatsWorker) Sensors(_ context.Context) ([]sensor.Entity, error) {
return sensors, nil
}

func (w *netStatsWorker) ID() string {
func (w *netStatsWorker) PreferencesID() string {
return preferencesID
}

Expand Down
2 changes: 1 addition & 1 deletion internal/linux/net/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (w *ConnectionsWorker) Events(ctx context.Context) (<-chan sensor.Entity, e
return sensorCh, nil
}

func (w *ConnectionsWorker) ID() string {
func (w *ConnectionsWorker) PreferencesID() string {
return preferencesID
}

Expand Down
6 changes: 3 additions & 3 deletions internal/preferences/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// method and an ID that uniquely identifies the worker (and its preferences
// file on disk).
type Worker[T any] interface {
ID() string
PreferencesID() string
DefaultPreferences() T
}

Expand All @@ -45,7 +45,7 @@ func SaveWorkerPreferences[T any](ctx context.Context, worker string, prefs T) e
func LoadWorkerPreferences[T any](ctx context.Context, worker Worker[T]) (T, error) {
// Load config from file. If the preferences cannot be loaded for any reason
// other than the preferences file does not exist , return an error.
data, err := os.ReadFile(workerPreferencesFile(ctx, worker.ID()))
data, err := os.ReadFile(workerPreferencesFile(ctx, worker.PreferencesID()))
if err != nil && !errors.Is(err, os.ErrNotExist) {
return *new(T), fmt.Errorf("could not read app preferences file: %w", err)
}
Expand All @@ -54,7 +54,7 @@ func LoadWorkerPreferences[T any](ctx context.Context, worker Worker[T]) (T, err
// for the worker.
if errors.Is(err, os.ErrNotExist) {
// Save the newly created preferences to disk.
if err := SaveWorkerPreferences(ctx, worker.ID(), worker.DefaultPreferences()); err != nil {
if err := SaveWorkerPreferences(ctx, worker.PreferencesID(), worker.DefaultPreferences()); err != nil {
return *new(T), fmt.Errorf("could not save default preferences: %w", err)
}

Expand Down

0 comments on commit 9f44702

Please sign in to comment.