{ "swagger": "2.0", "info": { "title": "文件服务", "description": "处理文件上传与获取", "version": "v1" }, "schemes": [ "http", "https" ], "consumes": [ "application/json" ], "produces": [ "application/json" ], "paths": { "/api/v1/files": { "get": { "summary": "文件获取接口 (如果是私有文件,通过此接口获取或重定向)", "operationId": "GetFile", "responses": { "200": { "description": "A successful response.", "schema": {} } }, "parameters": [ { "name": "key", "in": "query", "required": true, "type": "string" } ], "tags": [ "file" ], "consumes": [ "multipart/form-data" ] } }, "/api/v1/upload": { "post": { "summary": "文件上传接口", "operationId": "Upload", "responses": { "200": { "description": "A successful response.", "schema": { "$ref": "#/definitions/UploadResp" } } }, "parameters": [ { "name": "body", "description": " 上传请求参数(File文件流在Handler中通过 r.FormFile 获取)", "in": "body", "required": true, "schema": { "$ref": "#/definitions/UploadReq" } } ], "tags": [ "file" ], "consumes": [ "multipart/form-data" ] } } }, "definitions": { "GetFileReq": { "type": "object", "properties": { "key": { "type": "string" } }, "title": "GetFileReq", "required": [ "key" ] }, "UploadReq": { "type": "object", "properties": { "type": { "type": "string", "enum": [ "avatar", "chat", "post", "verification", "dispute" ], "description": " 文件类型限制" } }, "title": "UploadReq", "required": [ "type" ] }, "UploadResp": { "type": "object", "properties": { "url": { "type": "string", "description": " 返回 CDN 地址或访问地址" } }, "title": "UploadResp", "required": [ "url" ] } }, "securityDefinitions": { "apiKey": { "type": "apiKey", "description": "Enter JWT Bearer token **_only_**", "name": "Authorization", "in": "header" } } }