docs: 更新 README.md 文档
完整重写项目文档,包含以下内容: 主要更新: - 添加项目介绍和功能特性说明 - 新增 API 授权章节,说明密钥验证机制 - 提供完整的 API 接口列表和使用示例 - 添加项目结构说明和配置指南 - 包含开发、部署和测试指南 - 更新版本日志 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8a01af8953
commit
98a3701d54
248
README.md
248
README.md
@ -1,93 +1,225 @@
|
||||
# file_service
|
||||
# RustFS 文件存储系统
|
||||
|
||||
基于 RustFS S3 兼容存储的高性能文件服务系统,提供文件上传、下载、分片上传、存储桶管理等完整功能。
|
||||
|
||||
## 功能特性
|
||||
|
||||
## Getting started
|
||||
- ✅ **文件操作**: 上传、下载、删除、列表、预览
|
||||
- ✅ **分片上传**: 支持大文件分片上传,提高上传成功率
|
||||
- ✅ **存储桶管理**: 创建、列表、删除存储桶
|
||||
- ✅ **API 授权**: 所有 API 接口都需要密钥验证,保证安全性
|
||||
- ✅ **Swagger 文档**: 完整的 API 文档支持
|
||||
- ✅ **Web UI**: 提供简洁的 Web 界面
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
## 技术栈
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
- **框架**: Gin (Go Web Framework)
|
||||
- **存储**: RustFS S3 (AWS S3 Compatible)
|
||||
- **API 文档**: Swagger
|
||||
- **架构模式**: CQRS + Mediator
|
||||
|
||||
## Add your files
|
||||
## 快速开始
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
||||
### 环境要求
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin http://192.168.1.154:8888/root/file_service.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
- Go 1.23.2+
|
||||
- Docker (用于运行 RustFS 服务)
|
||||
|
||||
### 安装运行
|
||||
|
||||
```bash
|
||||
# 克隆项目
|
||||
git clone http://192.168.1.154:8888/root/file_service.git
|
||||
cd file_service
|
||||
|
||||
# 启动 RustFS 服务
|
||||
docker-compose up -d
|
||||
|
||||
# 编译并运行服务
|
||||
go run cmd/server/main.go
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
服务将在 `http://localhost:8080` 启动
|
||||
|
||||
- [ ] [Set up project integrations](http://192.168.1.154:8888/root/file_service/-/settings/integrations)
|
||||
### 访问地址
|
||||
|
||||
## Collaborate with your team
|
||||
- **Web UI**: http://localhost:8080/web
|
||||
- **API 文档**: http://localhost:8080/swagger/index.html
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
||||
## API 授权
|
||||
|
||||
## Test and Deploy
|
||||
### 安全性
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
所有 API 接口都需要通过授权验证才能访问。每个请求必须在请求头中包含有效的 API 密钥。
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
### 授权信息
|
||||
|
||||
***
|
||||
- **请求头**: `X-API-Key`
|
||||
- **密钥值**: `xn001624.`
|
||||
|
||||
# Editing this README
|
||||
### 使用示例
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
```bash
|
||||
# 列出所有存储桶
|
||||
curl -X GET http://localhost:8080/buckets \
|
||||
-H "X-API-Key: xn001624."
|
||||
|
||||
## Suggestions for a good README
|
||||
# 上传文件
|
||||
curl -X POST http://localhost:8080/files/upload \
|
||||
-H "X-API-Key: xn001624." \
|
||||
-F "file=@/path/to/file.txt" \
|
||||
-F "bucket=my-bucket" \
|
||||
-F "path=/uploads/"
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
# 下载文件
|
||||
curl -X GET "http://localhost:8080/files/download?bucket=my-bucket&path=/uploads/file.txt" \
|
||||
-H "X-API-Key: xn001624." \
|
||||
-o downloaded_file.txt
|
||||
```
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
### 错误响应
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
如果未提供或提供了无效的 API 密钥,将返回:
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
```json
|
||||
{
|
||||
"code": 401,
|
||||
"message": "未授权:请在请求头中提供有效的API密钥",
|
||||
"error": "Missing or invalid API key"
|
||||
}
|
||||
```
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
## API 接口
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
### 文件操作
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
| 接口 | 方法 | 描述 |
|
||||
|------|------|------|
|
||||
| `/files/upload` | POST | 上传文件 |
|
||||
| `/files/download` | GET | 下载文件 |
|
||||
| `/files/list` | GET | 列出文件 |
|
||||
| `/files/preview` | GET | 获取文件预览URL |
|
||||
| `/files/delete` | DELETE | 删除文件 |
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
### 分片上传
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
| 接口 | 方法 | 描述 |
|
||||
|------|------|------|
|
||||
| `/files/multipart/init` | POST | 初始化分片上传 |
|
||||
| `/files/multipart/part` | PUT | 上传分片 |
|
||||
| `/files/multipart/complete` | POST | 完成分片上传 |
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
### 存储桶操作
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
| 接口 | 方法 | 描述 |
|
||||
|------|------|------|
|
||||
| `/buckets` | POST | 创建存储桶 |
|
||||
| `/buckets` | GET | 列出存储桶 |
|
||||
| `/buckets` | DELETE | 删除存储桶 |
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
## 项目结构
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
```
|
||||
file_service/
|
||||
├── cmd/
|
||||
│ └── server/
|
||||
│ └── main.go # 程序入口
|
||||
├── internal/
|
||||
│ ├── api/
|
||||
│ │ ├── endpoints/ # API 端点定义
|
||||
│ │ ├── handlers/ # 请求处理器
|
||||
│ │ └── validators/ # 请求验证器
|
||||
│ ├── common/ # 公共配置和工具
|
||||
│ ├── domain/
|
||||
│ │ └── repository/ # 数据仓储接口
|
||||
│ ├── infrastructure/
|
||||
│ │ ├── mediator/ # CQRS Mediator 实现
|
||||
│ │ └── s3/ # S3 客户端实现
|
||||
│ └── middleware/
|
||||
│ └── auth.go # 授权中间件
|
||||
├── docs/
|
||||
│ └── AUTH_GUIDE.md # 授权使用指南
|
||||
├── web/ # Web UI 资源
|
||||
├── docker-compose.yml # Docker 编排配置
|
||||
├── Dockerfile # Docker 镜像构建
|
||||
└── .gitlab-ci.yml # CI/CD 配置
|
||||
```
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
## 配置
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
配置文件位于 `internal/common/config.go`,主要配置项:
|
||||
|
||||
```go
|
||||
type Config struct {
|
||||
ServerPort string // 服务端口
|
||||
RustFSEndpoint string // RustFS S3 端点
|
||||
RustFSAccessKey string // RustFS 访问密钥
|
||||
RustFSSecretKey string // RustFS 秘密密钥
|
||||
RustFSRegion string // S3 区域
|
||||
RustFSUseSSL bool // 是否使用 SSL
|
||||
}
|
||||
```
|
||||
|
||||
## 开发指南
|
||||
|
||||
### 编译项目
|
||||
|
||||
```bash
|
||||
go build -o file-service ./cmd/server/main.go
|
||||
```
|
||||
|
||||
### 运行测试
|
||||
|
||||
```bash
|
||||
go test ./...
|
||||
```
|
||||
|
||||
### 生成 Swagger 文档
|
||||
|
||||
```bash
|
||||
swag init -g cmd/server/main.go
|
||||
```
|
||||
|
||||
## 部署
|
||||
|
||||
### Docker 部署
|
||||
|
||||
```bash
|
||||
# 构建镜像
|
||||
docker build -t file-service:latest .
|
||||
|
||||
# 运行容器
|
||||
docker run -p 8080:8080 file-service:latest
|
||||
```
|
||||
|
||||
### Docker Compose 部署
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
## 文档
|
||||
|
||||
- [API 授权使用指南](docs/AUTH_GUIDE.md)
|
||||
- [Swagger API 文档](http://localhost:8080/swagger/index.html)
|
||||
|
||||
## 更新日志
|
||||
|
||||
### v1.1 (最新)
|
||||
- ✨ 添加 API 授权中间件,所有接口需要密钥验证
|
||||
- 📝 完善项目文档
|
||||
- 🔧 优化配置管理
|
||||
|
||||
### v1.0
|
||||
- 🎉 初始版本发布
|
||||
- ✨ 实现基础文件操作功能
|
||||
- ✨ 实现分片上传功能
|
||||
- ✨ 实现存储桶管理功能
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT License
|
||||
|
||||
## 联系方式
|
||||
|
||||
如有问题或建议,请提交 Issue 或 Merge Request。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user