这是从 Python FastAPI 迁移到 Go Gin 的版本。
src_go/ ├── cmd/ │ └── main.go # 应用入口 ├── config/ │ └── config.go # 配置管理 ├── database/ │ └── database.go # 数据库连接 ├── middleware/ │ ├── auth.go # 认证中间件 │ ├── cors.go # CORS中间件 │ └── ratelimit.go # 速率限制中间件 ├── models/ │ ├── base.go # 基础模型 │ ├── user.go # 用户模型 │ ├── content.go # 内容模型 │ └── stats.go # 统计模型 ├── routers/ │ ├── client.go # 客户端路由(用户相关) │ ├── api.go # API路由(信息统计) │ ├── ssg.go # SSG路由(静态站点生成) │ ├── glm.go # GLM AI路由 │ └── control.go # 控制路由(管理员) ├── services/ │ ├── content_service.go # 内容服务 │ └── user_service.go # 用户服务 ├── utils/ │ ├── session.go # Session管理 │ └── helpers.go # 辅助函数 ├── go.mod # Go模块定义 └── README.md # 本文件
| Python (SQLAlchemy) | Go (GORM) |
|---|---|
User | models.User |
UserSession | models.UserSession |
UserSettings | models.UserSettings |
Page | models.Page |
PageVersion | models.PageVersion |
Category | models.Category |
Comment | models.Comment |
Like | models.Like |
UserStats | models.UserStats |
ContentStats | models.ContentStats |
| ... | ... |
| Python (FastAPI) | Go (Gin) |
|---|---|
nextjs_router/client.py | routers/client.go |
nextjs_router/api/main.py | routers/api.go |
nextjs_router/ssg.py | routers/ssg.go |
nextjs_router/api/glm.py | routers/glm.go |
nextjs_router/control.py | routers/control.go |
cd src_go
go mod tidy
go run cmd/main.go
go build -o app cmd/main.go
./app
配置文件 .config.prod 应该位于项目根目录,格式为JSON。
GET /health - 健康检查POST /api/v1/users/laGuest - 访客登录POST /api/v1/users/laUser - 用户登录POST /api/v1/users/register - 用户注册GET /api/v1/users/profile - 获取用户信息GET /api/v1/info/website/stats/count - 获取站点统计GET /api/v1/info/cards - 获取卡片列表GET /api/v1/glm/models - 获取GLM模型列表