74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
//go:build wireinject
|
|
|
|
package bootstrap
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/goforj/wire"
|
|
|
|
"lincodex/backend/config"
|
|
httpadapter "lincodex/backend/internal/adapter/primary/http"
|
|
apiadapter "lincodex/backend/internal/adapter/primary/http/api"
|
|
httpmiddleware "lincodex/backend/internal/adapter/primary/http/middleware"
|
|
"lincodex/backend/internal/adapter/primary/http/problem"
|
|
v1 "lincodex/backend/internal/adapter/primary/http/v1"
|
|
"lincodex/backend/internal/adapter/secondary/postgres"
|
|
metrics "lincodex/backend/internal/adapter/secondary/prometheus"
|
|
redisadapter "lincodex/backend/internal/adapter/secondary/redis"
|
|
"lincodex/backend/internal/adapter/secondary/seaweedfs"
|
|
"lincodex/backend/internal/port/inbound"
|
|
"lincodex/backend/internal/port/outbound"
|
|
"lincodex/backend/internal/usecase/health"
|
|
)
|
|
|
|
// initialize receives the mail sender that start selected, so an unusable
|
|
// EMAIL_PROVIDER fails before any dependency is created.
|
|
func initialize(
|
|
ctx context.Context,
|
|
config config.Config,
|
|
logger *slog.Logger,
|
|
mailSender outbound.MailSender,
|
|
) (*Application, func(), error) {
|
|
wire.Build(
|
|
wire.NewSet(
|
|
postgres.NewHealthChecker,
|
|
redisadapter.NewCache,
|
|
seaweedfs.NewStorage,
|
|
wire.Bind(new(inbound.Readiness), new(*health.Readiness)),
|
|
wire.Bind(new(httpmiddleware.RequestMetrics), new(*metrics.Metrics)),
|
|
wire.Bind(new(apiadapter.Handler), new(*v1.Handler)),
|
|
wire.Bind(new(apiadapter.SecurityHandler), new(*v1.SessionSecurity)),
|
|
newReadiness,
|
|
metrics.New,
|
|
newHealthHandler,
|
|
problem.NewResponder,
|
|
newAPIHandler,
|
|
newTrustedProxies,
|
|
newIdentityHandler,
|
|
newSessionSecurity,
|
|
httpadapter.NewRouter,
|
|
newOutboxRelay,
|
|
newEventConsumers,
|
|
newJobWorker,
|
|
newMailSenderWorker,
|
|
newDeliveryMetrics,
|
|
NewApplication,
|
|
),
|
|
)
|
|
return nil, nil, nil
|
|
}
|
|
|
|
func newSessionSecurity(identityHandler *v1.IdentityHandler) *v1.SessionSecurity {
|
|
return identityHandler.SessionSecurity()
|
|
}
|
|
|
|
func newHealthHandler(readiness inbound.Readiness, config config.Config) *v1.HealthHandler {
|
|
return v1.NewHealthHandler(readiness, config.ReadinessTimeout)
|
|
}
|
|
|
|
func newReadiness(postgres *postgres.HealthChecker, cache *redisadapter.Cache, storage *seaweedfs.Storage) *health.Readiness {
|
|
return health.NewReadiness(postgres, cache, storage)
|
|
}
|