package main import ( "ankao/internal/handlers" "ankao/internal/middleware" "github.com/gin-gonic/gin" ) func main() { // 创建Gin路由器 r := gin.Default() // 应用自定义中间件 r.Use(middleware.Logger()) // 静态文件服务 r.Static("/static", "./web/static") r.StaticFile("/", "./web/index.html") // API路由组 api := r.Group("/api") { // 健康检查 api.GET("/health", handlers.HealthCheckHandler) // 题目相关API api.GET("/questions", handlers.GetQuestions) // 获取题目列表 api.GET("/questions/random", handlers.GetRandomQuestion) // 获取随机题目 api.GET("/questions/:id", handlers.GetQuestionByID) // 获取指定题目 api.POST("/submit", handlers.SubmitAnswer) // 提交答案 api.GET("/statistics", handlers.GetStatistics) // 获取统计数据 api.POST("/reset", handlers.ResetProgress) // 重置进度 } // 启动服务器 port := ":8080" if err := r.Run(port); err != nil { panic("服务器启动失败: " + err.Error()) } }