# growth-server **Repository Path**: epsos/growth-server ## Basic Information - **Project Name**: growth-server - **Description**: 个人成长观察与记录的仪表盘系统 (后端) - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-15 - **Last Updated**: 2026-03-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Growth Server - 后端服务 Growth 个人成长管理系统的后端服务,使用 Go + Gin + MongoDB 构建。 ## 技术栈 - **语言**: Go 1.22+ - **Web 框架**: Gin - **日志**: Zap - **数据库**: MongoDB 7.0+ - **数据库驱动**: go.mongodb.org/mongo-driver ## 功能特性 - 用户管理 API - 日记完整 CRUD 操作(创建、查询、更新、删除) - 日记批量导入 - 日记搜索(关键词、标签、日期范围) - 节日和个人纪念日管理 - 倒计时计算 - 完整的日志记录和错误处理 - CORS 支持 ## 项目结构 ``` growth-server/ ├── config/ # 配置模块 │ └── config.go # 配置加载 ├── handlers/ # API 处理函数 │ └── handlers.go # 所有 API 路由和处理 ├── logger/ # 日志模块 │ └── logger.go # Zap 日志初始化 ├── middleware/ # 中间件 │ └── middleware.go # CORS、日志、恢复中间件 ├── models/ # 数据模型 │ └── models.go # 数据结构定义和索引 ├── main.go # 入口文件 ├── go.mod # Go 模块定义 ├── .gitignore # Git 忽略文件 └── .env.example # 环境变量示例 ``` ## 环境变量 创建 `.env` 文件(参考 `.env.example`): ```env PORT=8080 GIN_MODE=debug MONGODB_URI=mongodb://localhost:27017 MONGODB_DB=growth ``` ## 快速开始 ### 前置条件 1. 安装 Go 1.22+ 2. 安装并启动 MongoDB 7.0+ ###安装依赖 ```bash go mod tidy ``` ### 运行服务 ```bash go run main.go ``` 服务将在 http://localhost:8080 启动 ###健康检查 访问 http://localhost:8080/health 检查服务状态 ## API 文档 ### 用户接口 #### 创建用户 ```http POST /api/users Content-Type: application/json { "username": "string", "timezone": "Asia/Shanghai" } ``` #### 获取用户 ```http GET /api/users/:id ``` #### 更新用户 ```http PUT /api/users/:id Content-Type: application/json { "username": "string", "preferences": { "theme": "light" } } ``` ### 日记接口 #### 创建日记 ```http POST /api/diaries Content-Type: application/json { "date": "2026-02-15", "content": "今天是个好日子...", "tags": ["工作", "生活"] } ``` #### 按日期查询日记 ```http GET /api/diaries?date=2026-02-15 ``` #### 列表所有日记 ```http GET /api/diaries/list ``` #### 更新日记 ```http PUT /api/diaries/:id Content-Type: application/json { "content": "更新后的内容..." } ``` #### 删除日记 ```http DELETE /api/diaries/:id ``` #### 批量导入日记 ```http POST /api/diaries/import Content-Type: application/json [ { "date": "2026-02-14", "content": "...", "tags": [] } ] ``` #### 搜索日记 ```http GET /api/diaries/search?q=关键词&tag=标签&start_date=2026-01-01&end_date=2026-12-31 ``` ### 节日接口 #### 获取节日列表 ```http GET /api/holidays?year=2026&month=02 ``` ### 时间标记接口 #### 创建标记 ```http POST /api/markers Content-Type: application/json { "title": "生日", "date": "2026-05-20", "description": "我的生日", "type": "birthday" } ``` #### 列表标记 ```http GET /api/markers ``` #### 获取倒计时 ```http GET /api/markers/countdown ``` #### 更新标记 ```http PUT /api/markers/:id ``` #### 删除标记 ```http DELETE /api/markers/:id ``` ## 数据模型 ### User(用户) ```go type User struct { ID primitive.ObjectID `bson:"_id,omitempty"` Username string Timezone string CreatedAt time.Time UpdatedAt time.Time Preferences UserPreferences } ``` ### DiaryEntry(日记条目) ```go type DiaryEntry struct { ID primitive.ObjectID `bson:"_id,omitempty"` Date string `bson:"date"` // 唯一索引 Content string Tags []string Metadata DiaryMetadata CreatedAt time.Time UpdatedAt time.Time } ``` ### TimeMarker(时间标记) ```go type TimeMarker struct { ID primitive.ObjectID `bson:"_id,omitempty"` Title string Date string Description string Type string CreatedAt time.Time } ``` ## 开发说明 ### 添加新的 API 1. 在 `models/models.go` 中定义数据模型 2. 在 `handlers/handlers.go` 中添加处理函数和路由 3. 在 `main.go` 中注册路由 ### 运行测试 (待补充) ## License MIT