Files
lunar-mini/server/cmd/main.go
T
gouki 01e67d4bea
Build and Deploy Server / build (push) Failing after 2s
feat(wish-tree): 许愿树游戏化改造
- 前端:全屏Canvas场景,夜空/云朵/草地/大树
- 前端:丝带系统,支持陀螺仪和麦克风交互
- 前端:弹幕许愿展示
- 前端:多棵树切换(祈福树/姻缘树/事业树)
- 后端:新增GET /api/wish/trees获取树列表
- 后端:新增GET /api/wish/tree/:id/wishes获取树许愿
- 后端:WishTree模型新增Type、Sort字段
- 后端:AutoMigrate自动处理表结构变更
- 后端:seedDefaultData自动初始化默认数据
- 数据库:wish_trees表新增type、sort字段
2026-08-07 12:56:48 +00:00

103 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"
"github.com/gouki/lunar-server/internal/config"
"github.com/gouki/lunar-server/internal/handler"
"github.com/gouki/lunar-server/internal/middleware"
"github.com/gouki/lunar-server/internal/service"
)
func main() {
// 加载配置
cfg := config.Load()
// 初始化数据库
if err := config.InitDB(cfg); err != nil {
log.Fatalf("Failed to initialize database: %v", err)
}
// 启动机器人许愿定时任务
wishService := service.NewWishService()
wishService.StartRobotWishJob()
// 设置运行模式
if cfg.Server.Env == "production" {
gin.SetMode(gin.ReleaseMode)
}
// 创建路由
r := gin.Default()
// 中间件
r.Use(middleware.CORS())
r.Use(middleware.Logger())
// 静态文件
r.Static("/static", "./web/static")
r.StaticFile("/", "./web/index.html")
// API 路由
api := r.Group("/api")
{
// 用户相关
user := api.Group("/user")
{
user.POST("/login", handler.UserLogin)
user.POST("/logout", handler.UserLogout)
user.GET("/profile", middleware.Auth(), handler.GetUserProfile)
user.PUT("/profile", middleware.Auth(), handler.UpdateUserProfile)
user.POST("/auth", handler.WechatAuth)
}
// 支付相关
pay := api.Group("/pay")
{
pay.POST("/create", middleware.Auth(), handler.CreateOrder)
pay.POST("/notify", handler.PayNotify)
pay.GET("/status/:orderId", handler.GetPayStatus)
}
// 订单相关
order := api.Group("/order")
{
order.GET("/list", middleware.Auth(), handler.GetOrderList)
order.GET("/:id", middleware.Auth(), handler.GetOrderDetail)
order.POST("/cancel/:id", middleware.Auth(), handler.CancelOrder)
}
// 许愿相关
wish := api.Group("/wish")
{
wish.GET("/trees", handler.GetWishTrees)
wish.GET("/tree", handler.GetWishTree)
wish.GET("/tree/:id/wishes", handler.GetTreeWishes)
wish.POST("/create", middleware.Auth(), handler.CreateWish)
wish.GET("/list", handler.GetWishList)
wish.GET("/:id", handler.GetWishDetail)
wish.DELETE("/:id", middleware.Auth(), handler.DeleteWish)
wish.GET("/products", handler.GetWishProducts)
}
}
// 管理后台路由(Inertia.js
admin := r.Group("/admin")
admin.Use(middleware.AdminAuth())
{
admin.GET("/", handler.AdminDashboard)
admin.GET("/users", handler.AdminUsers)
admin.GET("/orders", handler.AdminOrders)
admin.GET("/wishes", handler.AdminWishes)
admin.GET("/settings", handler.AdminSettings)
}
// 启动服务器
addr := ":" + cfg.Server.Port
log.Printf("Server starting on %s", addr)
if err := r.Run(addr); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}