refactor for separation of concern for better readabiliy and maintainability
This commit is contained in:
@@ -16,11 +16,9 @@ type InteractiveInitializer struct{}
|
||||
func (i InteractiveInitializer) Init(path string) error {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
// Path exists; assume already initialized.
|
||||
return nil
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
// Some other filesystem error; propagate it to the caller.
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ type AppBuilder struct {
|
||||
|
||||
func defaultBuilder(ctx context.Context, config Config) *AppBuilder {
|
||||
lifecycle := NewLifecycle()
|
||||
logger := newDefaultLogger(config, lifecycle)
|
||||
logger := defaultLogger(config, lifecycle)
|
||||
|
||||
return &AppBuilder{
|
||||
ctx: ctx,
|
||||
@@ -37,7 +37,7 @@ func defaultBuilder(ctx context.Context, config Config) *AppBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultLogger(config Config, lifecycle *Lifecycle) *slog.Logger {
|
||||
func defaultLogger(config Config, lifecycle *Lifecycle) *slog.Logger {
|
||||
statsDir := filepath.Dir(config.StatisticsStoragePath)
|
||||
if statsDir == "" {
|
||||
statsDir = "."
|
||||
|
||||
@@ -2,7 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -37,7 +37,7 @@ func (s *StatisticsService) Save(ctx context.Context) error {
|
||||
|
||||
func (s *StatisticsService) GetStatistics() (models.Statistics, error) {
|
||||
if s.storage.Data == nil {
|
||||
return models.Statistics{}, errors.New("statistics data not initialized")
|
||||
return models.Statistics{}, fmt.Errorf("statistics data not initialized")
|
||||
}
|
||||
return *s.storage.Data, nil
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func (s *StatisticsService) RecordTaskRun(ctx context.Context, run models.TaskRu
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if s.storage.Data == nil {
|
||||
return errors.New("statistics data not initialized")
|
||||
return fmt.Errorf("statistics data not initialized")
|
||||
}
|
||||
|
||||
stats := s.storage.Data
|
||||
|
||||
Reference in New Issue
Block a user