37 lines
818 B
Go

package bootstrap
import (
"context"
"fmt"
"chatapp3-golang/internal/config"
"chatapp3-golang/internal/integration"
"chatapp3-golang/internal/repo"
)
// App 聚合进程启动所需的基础依赖,避免 api 和 consumer 重复拼装。
type App struct {
Config config.Config
Repository *repo.Repository
Gateways integration.Gateways
}
// New 完成配置加载、存储初始化和下游网关装配。
func New(ctx context.Context) (*App, error) {
cfg := config.Load()
repository, err := repo.New(cfg)
if err != nil {
return nil, fmt.Errorf("init repository: %w", err)
}
if err := repository.Ping(ctx); err != nil {
return nil, fmt.Errorf("ping dependencies: %w", err)
}
return &App{
Config: cfg,
Repository: repository,
Gateways: integration.NewGateways(cfg),
}, nil
}