代码推送

This commit is contained in:
2026-09-09 02:39:57 +08:00
parent a112893947
commit 5e47757c73
24 changed files with 1156 additions and 226 deletions

View File

@@ -6,6 +6,7 @@ import (
"gotest/internal/config"
"gotest/internal/database"
"gotest/internal/geoip"
"gotest/internal/handler"
"gotest/internal/middleware"
@@ -27,6 +28,10 @@ func Setup(
appH *handler.AppHandler,
musicH *handler.MusicHandler,
dashboardH *handler.DashboardHandler,
customerH *handler.CustomerHandler,
accessLogH *handler.AccessLogHandler,
configH *handler.ConfigHandler,
ipLocationService *geoip.Service,
) *gin.Engine {
if cfg.Env.Name == "prod" {
gin.SetMode(gin.ReleaseMode)
@@ -34,12 +39,13 @@ func Setup(
r := gin.New()
// 全局中间件链(顺序:RequestID → Recover → Logger → CORS → RateLimit)
// 全局中间件链(顺序:RequestID → Recover → Logger → CORS → RateLimit → AccessLog)
r.Use(middleware.RequestID())
r.Use(middleware.Recover())
r.Use(middleware.Logger())
r.Use(middleware.CORS(&cfg.CORS))
r.Use(middleware.RateLimit(&cfg.RateLimit))
r.Use(middleware.AccessLog(db.DB, ipLocationService))
// 健康检查(含数据库就绪探针)
r.GET("/api/health", func(c *gin.Context) {
@@ -147,6 +153,15 @@ func Setup(
music.GET("/new", musicH.ListNew)
}
// 公开接口(无需认证)
// ...
// 客户信息收集(公开,无需认证)
customer := api.Group("/customer")
{
customer.POST("/submit", customerH.Submit)
}
// 需要登录的路由
authed := api.Group("")
authed.Use(middleware.JWTAuth(cfg.JWT.Secret))
@@ -180,6 +195,16 @@ func Setup(
admin.POST("/dashboard/:table", dashboardH.CreateItem)
admin.PUT("/dashboard/:table/:id", dashboardH.UpdateItem)
admin.DELETE("/dashboard/:table/:id", dashboardH.DeleteItem)
// 访问日志
admin.GET("/access-logs", accessLogH.ListLogs)
admin.GET("/access-logs/stats", accessLogH.GetStats)
admin.DELETE("/access-logs", accessLogH.DeleteLogs)
// 系统配置(webhook 等)
admin.GET("/config", configH.ListConfigs)
admin.GET("/config/:key", configH.GetConfig)
admin.PUT("/config/:key", configH.SetConfig)
}
}