refactor(backend): standardize errors and simplify configuration and test setup

This commit is contained in:
TakuyaYagam1 committed 2026-10-05 16:15:30 +03:00
1 parent 1535c19b8c
commit 138666a7bb
92 files changed
+3994 -210

No files matched your search

+22 -1
View File
@@ -13,6 +13,8 @@ import (
"lincodex/backend/internal/adapter/primary/http/v1"
"lincodex/backend/internal/adapter/secondary/postgres"
"lincodex/backend/internal/adapter/secondary/prometheus"
"lincodex/backend/internal/adapter/secondary/redis"
"lincodex/backend/internal/adapter/secondary/seaweedfs"
"lincodex/backend/internal/port/inbound"
"lincodex/backend/internal/usecase/health"
"log/slog"
@@ -25,16 +27,31 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger)
if err != nil {
return nil, nil, err
}
readiness := health.NewReadiness(healthChecker)
cache, cleanup2, err := redis.NewCache(config2, logger)
if err != nil {
cleanup()
return nil, nil, err
}
storage, cleanup3, err := seaweedfs.NewStorage(config2)
if err != nil {
cleanup2()
cleanup()
return nil, nil, err
}
readiness := newReadiness(healthChecker, cache, storage)
healthHandler := newHealthHandler(readiness, config2)
metrics := prometheus.New()
handler, err := httpadapter.NewRouter(healthHandler, metrics, logger)
if err != nil {
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
application := NewApplication(config2, handler, metrics, logger)
return application, func() {
cleanup3()
cleanup2()
cleanup()
}, nil
}
@@ -44,3 +61,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger)
func newHealthHandler(readiness inbound.Readiness, config2 config.Config) *v1.HealthHandler {
return v1.NewHealthHandler(readiness, config2.ReadinessTimeout)
}
func newReadiness(postgres2 *postgres.HealthChecker, cache *redis.Cache, storage *seaweedfs.Storage) *health.Readiness {
return health.NewReadiness(postgres2, cache, storage)
}