diff --git a/cmd/api/main.go b/cmd/api/main.go index 89ddbe1..77887fa 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -8,8 +8,8 @@ import ( "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" + qiniuhandler "wx_service/internal/common/qiniu/handler" + qiniuservice "wx_service/internal/common/qiniu/service" "wx_service/internal/database" "wx_service/internal/model" rmhandler "wx_service/internal/remove_watermark/handler" @@ -57,8 +57,8 @@ func main() { smokeLogService := smokeservice.NewSmokeLogService(database.DB) smokeHandler := smokehandler.NewSmokeHandler(smokeLogService) - qiniuService := commonservice.NewQiniuService(config.AppConfig.Qiniu) - uploadHandler := commonhandler.NewUploadHandler(qiniuService) + qiniuService := qiniuservice.NewQiniuService(config.AppConfig.Qiniu) + uploadHandler := qiniuhandler.NewUploadHandler(qiniuService) // 6) 注册路由:把 URL 映射到 handler routes.Register(router, database.DB, authHandler, videoHandler, smokeHandler, uploadHandler) diff --git a/internal/common/handler/upload_handler.go b/internal/common/qiniu/handler/upload_handler.go similarity index 84% rename from internal/common/handler/upload_handler.go rename to internal/common/qiniu/handler/upload_handler.go index ab74a7a..3af6ecf 100644 --- a/internal/common/handler/upload_handler.go +++ b/internal/common/qiniu/handler/upload_handler.go @@ -6,16 +6,16 @@ import ( "github.com/gin-gonic/gin" - "wx_service/internal/common/service" + qiniuservice "wx_service/internal/common/qiniu/service" "wx_service/internal/middleware" "wx_service/internal/model" ) type UploadHandler struct { - qiniuService *service.QiniuService + qiniuService *qiniuservice.QiniuService } -func NewUploadHandler(qiniuService *service.QiniuService) *UploadHandler { +func NewUploadHandler(qiniuService *qiniuservice.QiniuService) *UploadHandler { return &UploadHandler{qiniuService: qiniuService} } @@ -38,7 +38,7 @@ func (h *UploadHandler) QiniuToken(c *gin.Context) { token, err := h.qiniuService.CreateUploadToken(user.MiniProgramID, user.ID, req.Filename) if err != nil { - if errors.Is(err, service.ErrQiniuNotConfigured) { + if errors.Is(err, qiniuservice.ErrQiniuNotConfigured) { c.JSON(http.StatusServiceUnavailable, model.Error(http.StatusServiceUnavailable, "未配置七牛上传服务,请联系管理员")) return } diff --git a/internal/common/service/qiniu_service.go b/internal/common/qiniu/service/qiniu_service.go similarity index 100% rename from internal/common/service/qiniu_service.go rename to internal/common/qiniu/service/qiniu_service.go diff --git a/internal/routes/common_routes.go b/internal/routes/common_routes.go index fdc806e..6a2778a 100644 --- a/internal/routes/common_routes.go +++ b/internal/routes/common_routes.go @@ -3,10 +3,10 @@ package routes import ( "github.com/gin-gonic/gin" - commonhandler "wx_service/internal/common/handler" + qiniuhandler "wx_service/internal/common/qiniu/handler" ) -func registerCommonRoutes(protected *gin.RouterGroup, uploadHandler *commonhandler.UploadHandler) { +func registerCommonRoutes(protected *gin.RouterGroup, uploadHandler *qiniuhandler.UploadHandler) { // 公共接口(所有小程序共用) common := protected.Group("/common") { diff --git a/internal/routes/routes.go b/internal/routes/routes.go index 7e94dcc..c3cfbc9 100644 --- a/internal/routes/routes.go +++ b/internal/routes/routes.go @@ -7,7 +7,7 @@ import ( "gorm.io/gorm" authhandler "wx_service/internal/common/auth/handler" - commonhandler "wx_service/internal/common/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" @@ -19,7 +19,7 @@ func Register( authHandler *authhandler.AuthHandler, videoHandler *rmhandler.VideoHandler, smokeHandler *smokehandler.SmokeHandler, - uploadHandler *commonhandler.UploadHandler, + uploadHandler *qiniuhandler.UploadHandler, ) { // Register 用来集中注册所有 HTTP 路由,便于工程结构更清晰: // - main 只负责初始化(配置/DB/依赖注入)