AnCao/main.go
yanlongqi f791c235e1 添加题目练习功能模块
实现了完整的题目练习功能,包括后端API和前端界面:
- 后端新增题目管理handlers和数据模型
- 前端新增题目展示页面和API调用模块
- 添加题库数据文件支持
- 更新路由配置以集成新功能

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 20:26:53 +08:00

42 lines
1.0 KiB
Go

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())
}
}