refactor services to use Interface and change name to app

This commit is contained in:
Robin Olsen
2026-02-22 16:16:09 +01:00
parent dbf619a054
commit 118e67dbf4
36 changed files with 247 additions and 219 deletions

View File

@@ -2,8 +2,8 @@ package service
import (
"context"
"database/sql"
"fmt"
"log/slog"
"os"
"time"
@@ -15,14 +15,7 @@ import (
"github.com/steveyegge/beads"
)
type Services struct {
Config Config
DB *sql.DB
Beads *BeadsService
Statistics *StatisticsService
}
func NewServices(ctx context.Context, config Config) (*Services, func(), error) {
func NewServices(ctx context.Context, config Config) (*App, func(), error) {
var cleanupFuncs []func()
if !initialized(config.BeadsDBPath) {
@@ -47,16 +40,18 @@ func NewServices(ctx context.Context, config Config) (*Services, func(), error)
StartTime: time.Now(),
})
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
statSvc, err := NewStatisticsService(statStore)
if err != nil {
return nil, nil, err
}
return &Services{
DB: beadsSvc.UnderlyingDB(),
Beads: beadsSvc,
Statistics: statSvc,
Config: config,
return &App{
Issues: beadsSvc,
Stats: statSvc,
Config: config,
Logger: logger,
}, func() { runCleanup(cleanupFuncs) }, nil
}