AnCao/main.go
yanlongqi 92e8c9a94c 实现完整的登录注册功能并优化前端组件
- 实现登录页面:
  - 添加登录和注册表单切换功能
  - 使用antd-mobile组件(Form, Input, Button, Toast)
  - 白色背景设计,标题使用主题色
  - 表单验证和错误提示
  - 已登录用户自动重定向

- 完善用户认证:
  - 路由保护,未登录用户重定向到登录页
  - 用户信息保存到localStorage
  - Profile页面支持退出登录

- 后端改进:
  - 启用CORS中间件支持跨域请求

- 更新开发规范:
  - 在CLAUDE.md中添加前端开发规范
  - 明确UI组件使用原则:优先使用antd-mobile组件

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

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

47 lines
1.2 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.CORS())
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.POST("/login", handlers.Login) // 用户登录
api.POST("/register", handlers.Register) // 用户注册
// 题目相关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())
}
}