Files
wx_service/cmd/api/main.go
T
nepiedg 1c48fbdeaf Integrate WeChat Official Account support and update configuration
- Added WeChat Official Account configuration options to .env.example and config.go for OAuth2 integration.
- Updated main.go to initialize WeChat OAuth handler and register routes for handling OAuth requests.
- Enhanced documentation to include references for WeChat Official Account functionality.
- Updated route registration to accommodate the new OAuth handler for improved API structure.
2025-12-31 03:55:30 +00:00

77 lines
2.6 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"
qiniuhandler "wx_service/internal/common/qiniu/handler"
qiniuservice "wx_service/internal/common/qiniu/service"
oahandler "wx_service/internal/common/wechat_official/handler"
oaservice "wx_service/internal/common/wechat_official/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 := qiniuservice.NewQiniuService(config.AppConfig.Qiniu)
uploadHandler := qiniuhandler.NewUploadHandler(qiniuService)
oaService := oaservice.NewWeChatOAService(config.AppConfig.WeChatOA)
oaOAuthHandler := oahandler.NewOAuthHandler(oaService)
// 6) 注册路由:把 URL 映射到 handler
routes.Register(router, database.DB, authHandler, videoHandler, smokeHandler, uploadHandler, oaOAuthHandler)
// 7) 启动监听端口
addr := ":" + config.AppConfig.Server.Port
if err := router.Run(addr); err != nil {
log.Fatalf("server stopped: %v", err)
}
}