chore: apply task changes
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||||
internalMiddleware "github.com/break/junhong_cmp_fiber/internal/middleware"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/verification"
|
||||
@@ -62,7 +63,10 @@ func main() {
|
||||
// 8. 初始化对象存储服务(可选)
|
||||
storageSvc := initStorage(cfg, appLogger)
|
||||
|
||||
// 9. 初始化所有业务组件(通过 Bootstrap)
|
||||
// 9. 初始化 Gateway 客户端(可选)
|
||||
gatewayClient := initGateway(cfg, appLogger)
|
||||
|
||||
// 10. 初始化所有业务组件(通过 Bootstrap)
|
||||
result, err := bootstrap.Bootstrap(&bootstrap.Dependencies{
|
||||
DB: db,
|
||||
Redis: redisClient,
|
||||
@@ -72,24 +76,25 @@ func main() {
|
||||
VerificationService: verificationSvc,
|
||||
QueueClient: queueClient,
|
||||
StorageService: storageSvc,
|
||||
GatewayClient: gatewayClient,
|
||||
})
|
||||
if err != nil {
|
||||
appLogger.Fatal("初始化业务组件失败", zap.Error(err))
|
||||
}
|
||||
|
||||
// 10. 创建 Fiber 应用
|
||||
// 11. 创建 Fiber 应用
|
||||
app := createFiberApp(cfg, appLogger)
|
||||
|
||||
// 11. 注册中间件
|
||||
// 12. 注册中间件
|
||||
initMiddleware(app, cfg, appLogger)
|
||||
|
||||
// 12. 注册路由
|
||||
// 13. 注册路由
|
||||
initRoutes(app, cfg, result, queueClient, db, redisClient, appLogger)
|
||||
|
||||
// 13. 生成 OpenAPI 文档
|
||||
// 14. 生成 OpenAPI 文档
|
||||
generateOpenAPIDocs("logs/openapi.yaml", appLogger)
|
||||
|
||||
// 14. 启动服务器
|
||||
// 15. 启动服务器
|
||||
startServer(app, cfg, appLogger)
|
||||
}
|
||||
|
||||
@@ -327,3 +332,22 @@ func initStorage(cfg *config.Config, appLogger *zap.Logger) *storage.Service {
|
||||
|
||||
return storage.NewService(provider, &cfg.Storage)
|
||||
}
|
||||
|
||||
func initGateway(cfg *config.Config, appLogger *zap.Logger) *gateway.Client {
|
||||
if cfg.Gateway.BaseURL == "" {
|
||||
appLogger.Info("Gateway 未配置,跳过初始化")
|
||||
return nil
|
||||
}
|
||||
|
||||
client := gateway.NewClient(
|
||||
cfg.Gateway.BaseURL,
|
||||
cfg.Gateway.AppID,
|
||||
cfg.Gateway.AppSecret,
|
||||
).WithTimeout(time.Duration(cfg.Gateway.Timeout) * time.Second)
|
||||
|
||||
appLogger.Info("Gateway 客户端初始化成功",
|
||||
zap.String("base_url", cfg.Gateway.BaseURL),
|
||||
zap.String("app_id", cfg.Gateway.AppID))
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user