2025-11-14 08:42:26 +08:00
|
|
|
//go:build wireinject
|
|
|
|
|
// +build wireinject
|
|
|
|
|
|
|
|
|
|
package di
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"caatsm/internal/adapter/parser"
|
|
|
|
|
"caatsm/internal/app"
|
|
|
|
|
"caatsm/internal/infra/config"
|
|
|
|
|
"caatsm/internal/infra/log"
|
2025-11-15 16:30:29 +08:00
|
|
|
"caatsm/internal/infra/monitoring"
|
2025-11-14 08:42:26 +08:00
|
|
|
"caatsm/internal/infra/nats"
|
|
|
|
|
"caatsm/internal/infra/postgres"
|
2025-11-17 11:47:23 +08:00
|
|
|
"caatsm/internal/infra/telemetry"
|
2025-11-14 08:42:26 +08:00
|
|
|
|
|
|
|
|
"github.com/google/wire"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// InitializeApp initializes the application with all dependencies
|
2025-11-15 16:30:29 +08:00
|
|
|
func InitializeApp() (*app.MessageProcessor, *nats.Consumer, *monitoring.Server, error) {
|
2025-11-15 09:01:24 +08:00
|
|
|
comps, err := buildAppComponents()
|
|
|
|
|
if err != nil {
|
2025-11-15 16:30:29 +08:00
|
|
|
return nil, nil, nil, err
|
2025-11-15 09:01:24 +08:00
|
|
|
}
|
2025-11-15 16:30:29 +08:00
|
|
|
return comps.Processor, comps.Consumer, comps.Monitoring, nil
|
2025-11-15 09:01:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// InitializeAppWithConfig wires dependencies using a pre-loaded configuration.
|
2025-11-15 16:30:29 +08:00
|
|
|
func InitializeAppWithConfig(cfg *config.Config) (*app.MessageProcessor, *nats.Consumer, *monitoring.Server, error) {
|
2025-11-15 09:01:24 +08:00
|
|
|
comps, err := buildAppComponentsWithConfig(cfg)
|
|
|
|
|
if err != nil {
|
2025-11-15 16:30:29 +08:00
|
|
|
return nil, nil, nil, err
|
2025-11-15 09:01:24 +08:00
|
|
|
}
|
2025-11-15 16:30:29 +08:00
|
|
|
return comps.Processor, comps.Consumer, comps.Monitoring, nil
|
2025-11-15 09:01:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var runtimeSet = wire.NewSet(
|
|
|
|
|
// Logger
|
|
|
|
|
log.ProvideLogger,
|
|
|
|
|
|
|
|
|
|
// Database
|
|
|
|
|
postgres.ProvideDB,
|
|
|
|
|
postgres.ProvideRepository,
|
2025-11-14 21:42:04 +08:00
|
|
|
|
2025-11-15 09:01:24 +08:00
|
|
|
// NATS
|
|
|
|
|
nats.ProvideNATSConn,
|
|
|
|
|
nats.ProvideJetStream,
|
|
|
|
|
nats.ProvidePublisher,
|
2025-11-14 21:42:04 +08:00
|
|
|
|
2025-11-15 09:01:24 +08:00
|
|
|
// Parser
|
|
|
|
|
parser.ProvideParser,
|
2025-11-14 21:42:04 +08:00
|
|
|
|
2025-11-16 13:14:46 +08:00
|
|
|
// Telemetry
|
|
|
|
|
telemetry.ProvideRecorder,
|
|
|
|
|
|
2025-11-15 09:01:24 +08:00
|
|
|
// App
|
|
|
|
|
app.NewMessageProcessor,
|
2025-11-14 21:42:04 +08:00
|
|
|
|
2025-11-15 09:01:24 +08:00
|
|
|
// Consumer
|
|
|
|
|
nats.ProvideConsumer,
|
2025-11-15 16:30:29 +08:00
|
|
|
|
|
|
|
|
// Monitoring HTTP server
|
|
|
|
|
monitoring.ProvideServer,
|
2025-11-15 09:01:24 +08:00
|
|
|
)
|
2025-11-14 21:42:04 +08:00
|
|
|
|
2025-11-15 09:01:24 +08:00
|
|
|
func buildAppComponents() (*appComponents, error) {
|
|
|
|
|
wire.Build(
|
|
|
|
|
config.ProvideConfig,
|
|
|
|
|
runtimeSet,
|
|
|
|
|
wire.Struct(new(appComponents), "*"),
|
|
|
|
|
)
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
2025-11-14 21:42:04 +08:00
|
|
|
|
2025-11-15 09:01:24 +08:00
|
|
|
func buildAppComponentsWithConfig(cfg *config.Config) (*appComponents, error) {
|
|
|
|
|
wire.Build(
|
|
|
|
|
runtimeSet,
|
|
|
|
|
wire.Struct(new(appComponents), "*"),
|
2025-11-14 08:42:26 +08:00
|
|
|
)
|
2025-11-15 09:01:24 +08:00
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type appComponents struct {
|
|
|
|
|
Processor *app.MessageProcessor
|
|
|
|
|
Consumer *nats.Consumer
|
2025-11-15 16:30:29 +08:00
|
|
|
Monitoring *monitoring.Server
|
2025-11-14 08:42:26 +08:00
|
|
|
}
|