bba6dc6b4f
- Replaced common upload handler and service with Qiniu-specific implementations in main.go and route registration. - Deleted outdated upload_handler.go and qiniu_service.go files to streamline the codebase. - Updated route definitions to utilize the new Qiniu upload handler for improved file upload management.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package routes
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
"gorm.io/gorm"
|
||
|
||
authhandler "wx_service/internal/common/auth/handler"
|
||
qiniuhandler "wx_service/internal/common/qiniu/handler"
|
||
"wx_service/internal/middleware"
|
||
rmhandler "wx_service/internal/remove_watermark/handler"
|
||
smokehandler "wx_service/internal/smoke/handler"
|
||
)
|
||
|
||
func Register(
|
||
router *gin.Engine,
|
||
db *gorm.DB,
|
||
authHandler *authhandler.AuthHandler,
|
||
videoHandler *rmhandler.VideoHandler,
|
||
smokeHandler *smokehandler.SmokeHandler,
|
||
uploadHandler *qiniuhandler.UploadHandler,
|
||
) {
|
||
// Register 用来集中注册所有 HTTP 路由,便于工程结构更清晰:
|
||
// - main 只负责初始化(配置/DB/依赖注入)
|
||
// - routes 只负责把 URL 映射到 handler
|
||
api := router.Group("/api/v1")
|
||
{
|
||
// 登录接口:用微信 code 换取/创建用户并返回 session_key(作为后续 Bearer Token)
|
||
api.POST("/auth/login", authHandler.LoginWithWeChat)
|
||
|
||
// 需要登录的接口组:统一挂载鉴权中间件
|
||
protected := api.Group("")
|
||
protected.Use(middleware.AuthMiddleware(db))
|
||
{
|
||
registerCommonRoutes(protected, uploadHandler)
|
||
registerRemoveWatermarkRoutes(protected, videoHandler)
|
||
registerSmokeRoutes(protected, smokeHandler)
|
||
}
|
||
}
|
||
|
||
// 健康检查:用于容器/负载均衡探活
|
||
router.GET("/healthz", func(c *gin.Context) {
|
||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||
})
|
||
}
|