基于 golang + gin 的简单文件系统
0.0.0.0: 8000
用于 http 资源请求, 只能访问,不能上传
默认挂载目录: /var/www/filesystem
可以直接通过 web 端进行访问
- 下载
下载条件:
- bucker1 桶下有 test.txt 文件
- bucket1 属性为公有可访问
http://localhost:8000/bucket1/test.txt
0.0.0.0: 8001
api 服务需要进行身份认证, 需要在请求头添加 user,auth 进行身份认证
user 等级: system: 默认会自动生成一个 system 用户 admin: 管理用户 user: 不同用户, 只对自己创建的桶拥有权限
- 添加用户
curl -X POST "${URL}/user" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
--header 'Content-Type: application/json' \
--data-raw '{"name": "i-curve","u_type": 2}'- 删除用户
curl -X DELETE "${URL}/user" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
--header 'Content-Type: application/json' \
--data-raw '{"name": "i-curve"}'- 创建 bucket
curl -X POST "${URL}/bucket" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
--header 'Content-Type: application/json' \
--data-raw '{"name": "bucket2", "b_type": 3}'- 删除 bucket
curl -X DELETE "${URL}/bucket" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
--header 'Content-Type: application/json' \
--data-raw '{"name": "bucket2"}'- 获取所有 bucket
curl -X GET "${URL}/bucket" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
--header 'Content-Type: application/json'- 获取文件目录
curl -X GET "${URL}/file/catalog?path={path}" \
--header "user: ${USER}" \
--header "auth: ${AUTH}"- 文件上传
上传 a.txt 文件到 bucket1 的 test/01 内
curl -X POST "${URL}/file/upload" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
-F "file=@/root/a.txt" \
-F "bucket=bucket1" \
-F "key=/test/a.txt"- 文件下载
curl -X GET "${URL}/file/download?bucket=bucket1&key=/test/a.txt" \
--header "user: ${USER}" \
--header "auth: ${AUTH}"- 文件删除
curl -X DELETE "${URL}/file/delete" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
-d '{"bucket": "bucket", "key": "/test/01"}'- 文件移动
curl -X POST "${URL}/file/move" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
--header "Content-Type: application/json" \
-d '{"s_bucket": "bucket1",
"s_key": "test/a.txt","d_bucket": "bucket1","d_key":"test/b.txt"}'- 文件复制
curl -X POST "${URL}/file/copy" \
--header "user: ${USER}" \
--header "auth: ${AUTH}" \
--header "Content-Type: application/json" \
-d '{"s_bucket":"bucket1","s_key":"test/a.txt","d_bucket": "bucket1","d_key": "new_path/dd/b.txt"}'管理接口
当进行数据库更改后, 并不会直接生效, 需要进行权限刷新
curl -X POST "${URL}/refresh" \
--header "user: ${USER}" \
--header "auth: ${AUTH}"- 获取版本信息
curl "${URL}/version" \
--header "user: ${USER}" \
--header "auth: ${AUTH}"repo: https://github.com/i-curve/filesystem-gosdk
repo: https://github.com/i-curve/filesystem-pysdk
repo: https://github.com/i-curve/filesystem-shell
克隆项目
git clone https://github.com/i-curve/filesystem.git生成可执行文件 filesystem
cd filesystem && make构建 docker 镜像
make docker拉取镜像
docker pull wjuncurve/filesystem:latestdocker run --name filesystem -d \
-p 8000:8000 -p 8001:8001 \
-e "MYSQL_HOST=host.docker.internal" \
filesystem| 变量名 | 说明 |
|---|---|
| LANGUAGE | 程序运行语言,默认 zh 中文(en 可选) |
| MODE | 运行模式 (DEBUG | RELEASE) |
| BASE_DIR | 默认程序存储目录为(/var/www/filesystem) |
| MYSQL_HOST | 数据库地址 |
| MYSQL_USER | 数据库用户 |
| MYSQL_PASSWORD | 数据库密码 |
| MYSQL_PORT | 数据库端口 |
| DATABASE | 数据库名 (默认 filesystem) |
查看版本信息
curl "http://localhost:8001/version"查看生成 system 用户信息
docker logs filesystemsystem user
user: system
auth: d6837f276686cbfe4852c8d8c5104f59