PORT=8080 go run ./cmd/server
https://{host}/{org}/{repo}.gitmain.go 修改)除原始文件下载外,所有接口返回:
{ "code": 200, "message": "ok", "data": { ... } }
code=200,message=okcode=HTTP 状态码,message=错误说明X-Git-Username、X-Git-Password:远端 BasicAuth。公开仓库的读接口可不传;写接口必传。X-Git-Author、X-Git-Email:写操作的作者信息。未提供时默认:Name=restful2git,Email=noreply@{host};作者名优先取 X-Git-Author。GET /git/{host}/tree/{repo}?ref=&path=GET /git/{host}/files/{repo}?ref=&path=&raw=&download=
raw=true 时自动识别 MIME,并可通过 download=true 控制 Content-DispositionGET /git/{host}/commits/{repo}?ref=&limit=GET /git/{host}/commit/{sha}/{repo}?ref=&patch=(可选返回 patch)GET /git/{host}/compare/{repo}?from=&to=&patch=GET /git/{host}/diff/{repo}?ref=&path=(自动加深浅克隆以获取父提交)GET /git/{host}/branches/{repo}GET /git/{host}/tags/{repo}PUT /git/{host}/files/{repo}
path, content(base64|text), encoding(base64|text=默认base64), ref, [message], [author], [baseCommit], [lfs]message 自动生成:新增 feat: add {path},更新 chore: update {path}DELETE /git/{host}/files/{repo}
path, ref, [message], [author], [baseCommit]POST /git/{host}/files:move/{repo}
from, to, ref, [message], [author], [baseCommit]message 自动生成:chore: move {from} -> {to}POST /git/{host}/upload/{repo}
file(binary), path, ref, [message], [author], [lfs]lfs=true 时自动使用 LFS batch 与上传;若对象已存在,写入指针文件(避免 502)POST /git/{host}/branches/{repo}(body: name, from)DELETE /git/{host}/branches/{name}/{repo}(直接 remote push 删除)POST /git/{host}/tags/{repo}(body: name, from,存在则 409)DELETE /git/{host}/tags/{name}/{repo}(直接 remote push 删除)X-Git-Username/PasswordbaseCommit 不匹配)、无内容可提交(no changes to commit)、标签已存在仓库不存在时统一:{ "code": 404, "message": "repository not found" }
main.go:Gin 入口、路由、限流internal/http/handlers.go:业务处理(树、文件、提交、对比、分支、标签、上传等)internal/http/response.go:统一响应封装internal/lfs/client.go:LFS batch 客户端(upload/download,pointer 处理)关键特性:
go build ./...
PORT=8080 ./restful2git # 或 go run ./cmd/server
容器化与系统化部署可将 PORT、反向代理(TLS/鉴权)置于网关层。
本项目采用 MIT License。