jdysya 5cb134fa9d refactor(gateway): 重构 main.go 文件
- 移除日志初始化代码,改为使用 utils.InitLogger()
- 删除用户模型定义,移至 models 包
- 抽离路由处理逻辑到 handlers 包
- 使用 middleware 包中的 AuthRequired 中间件
- 优化数据库连接和迁移逻辑
- 简化 main 函数,提高代码可读性和维护性
2025-02-15 20:16:44 +08:00

28 lines
610 B
Go

package handlers
import (
"net/http"
"os"
"gateway/utils"
"github.com/gin-gonic/gin"
)
// 处理首页请求
func ServeIndex(c *gin.Context) {
utils.LogAccess(c.ClientIP(), c.Request.URL.Path, c.Request.Method)
http.ServeFile(c.Writer, c.Request, "./static/index.html")
}
// 处理静态文件请求
func ServeStatic(c *gin.Context) {
utils.LogAccess(c.ClientIP(), c.Request.URL.Path, c.Request.Method)
filePath := "./static" + c.Request.URL.Path
if _, err := os.Stat(filePath); err == nil {
http.ServeFile(c.Writer, c.Request, filePath)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
}