Files
wx_service/cmd/api/main.go
T
nepiedg cd7ae5ac56 Integrate Qiniu upload service and update configuration
- Added Qiniu configuration options to .env.example and config.go for file uploads.
- Refactored main.go to include new Qiniu service and upload handler.
- Updated route registration to accommodate the new upload handler.
- Enhanced documentation to include references for Qiniu upload functionality.
- Removed legacy authentication handler and services to streamline the codebase.
2025-12-31 03:18:03 +00:00

72 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"log"
"github.com/gin-gonic/gin"
"wx_service/config"
authhandler "wx_service/internal/common/auth/handler"
authservice "wx_service/internal/common/auth/service"
commonhandler "wx_service/internal/common/handler"
commonservice "wx_service/internal/common/service"
"wx_service/internal/database"
"wx_service/internal/model"
rmhandler "wx_service/internal/remove_watermark/handler"
rmmodel "wx_service/internal/remove_watermark/model"
rmservice "wx_service/internal/remove_watermark/service"
"wx_service/internal/routes"
smokehandler "wx_service/internal/smoke/handler"
smokemodel "wx_service/internal/smoke/model"
smokeservice "wx_service/internal/smoke/service"
)
func main() {
// 1) 加载配置(通常来自环境变量 / .env)
config.LoadConfig()
// 2) 初始化数据库连接
if err := database.InitDB(); err != nil {
log.Fatalf("init database failed: %v", err)
}
// 3) 自动建表/迁移(开发阶段很方便;生产环境可改为手动迁移)
if err := database.AutoMigrate(
&model.MiniProgram{},
&model.User{},
&rmmodel.VideoParseLog{},
&rmmodel.VideoParseUnlock{},
&smokemodel.SmokeLog{},
); err != nil {
log.Fatalf("auto migrate failed: %v", err)
}
// 4) 初始化 HTTP 框架(Gin
gin.SetMode(config.AppConfig.Server.Mode)
router := gin.Default()
// 5) 依赖注入:先创建 service,再创建 handlerhandler 只关心 HTTP 输入/输出)
miniProgramService := authservice.NewMiniProgramService(database.DB)
authService := authservice.NewAuthService(database.DB, miniProgramService)
authHandler := authhandler.NewAuthHandler(authService)
videoService, err := rmservice.NewVideoService(database.DB, config.AppConfig.ShortVideo)
if err != nil {
log.Fatalf("init video service failed: %v", err)
}
videoHandler := rmhandler.NewVideoHandler(videoService)
smokeLogService := smokeservice.NewSmokeLogService(database.DB)
smokeHandler := smokehandler.NewSmokeHandler(smokeLogService)
qiniuService := commonservice.NewQiniuService(config.AppConfig.Qiniu)
uploadHandler := commonhandler.NewUploadHandler(qiniuService)
// 6) 注册路由:把 URL 映射到 handler
routes.Register(router, database.DB, authHandler, videoHandler, smokeHandler, uploadHandler)
// 7) 启动监听端口
addr := ":" + config.AppConfig.Server.Port
if err := router.Run(addr); err != nil {
log.Fatalf("server stopped: %v", err)
}
}