Files
wx_service/cmd/api/main.go
T
nepiedg 97cadb033e Add short video configuration and related API endpoints
- Updated .env.example to include SHORT_VIDEO_API_KEY, SHORT_VIDEO_FREE_QUOTA, and SHORT_VIDEO_TIMEOUT_SECONDS.
- Enhanced main.go to auto-migrate new VideoParseLog and VideoParseUnlock models.
- Introduced VideoService and VideoHandler for handling video-related operations.
- Added protected API routes for removing watermarks and unlocking video features.
- Updated config.go to support short video configuration settings.
- Expanded documentation to reflect new features and configuration options.
2025-12-30 00:31:41 +00:00

59 lines
1.6 KiB
Go

package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
"wx_service/config"
"wx_service/internal/database"
"wx_service/internal/handler"
"wx_service/internal/middleware"
"wx_service/internal/model"
"wx_service/internal/service"
)
func main() {
config.LoadConfig()
if err := database.InitDB(); err != nil {
log.Fatalf("init database failed: %v", err)
}
if err := database.AutoMigrate(&model.MiniProgram{}, &model.User{}, &model.VideoParseLog{}, &model.VideoParseUnlock{}); err != nil {
log.Fatalf("auto migrate failed: %v", err)
}
gin.SetMode(config.AppConfig.Server.Mode)
router := gin.Default()
miniProgramService := service.NewMiniProgramService(database.DB)
authService := service.NewAuthService(database.DB, miniProgramService)
authHandler := handler.NewAuthHandler(authService)
videoService, err := service.NewVideoService(database.DB, config.AppConfig.ShortVideo)
if err != nil {
log.Fatalf("init video service failed: %v", err)
}
videoHandler := handler.NewVideoHandler(videoService)
api := router.Group("/api/v1")
{
api.POST("/auth/login", authHandler.LoginWithWeChat)
protected := api.Group("")
protected.Use(middleware.AuthMiddleware(database.DB))
{
protected.POST("/video/remove_watermark", videoHandler.RemoveWatermark)
protected.POST("/video/remove_watermark/unlock", videoHandler.UnlockQuota)
}
}
router.GET("/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
addr := ":" + config.AppConfig.Server.Port
if err := router.Run(addr); err != nil {
log.Fatalf("server stopped: %v", err)
}
}