1d799ac0e7
- 移除 swagger.json/yaml 中硬编码的 host 字段 - 在 docs.go 中将 Host 设置为空字符串以支持动态检测 - 添加前端 /swagger 代理配置,支持开发环境访问 Swagger UI - 在 main.go 中导入 docs 包注册 Swagger 文档
367 lines
12 KiB
Go
367 lines
12 KiB
Go
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
||
package docs
|
||
|
||
import "github.com/swaggo/swag"
|
||
|
||
const docTemplate = `{
|
||
"schemes": {{ marshal .Schemes }},
|
||
"swagger": "2.0",
|
||
"info": {
|
||
"description": "{{escape .Description}}",
|
||
"title": "{{.Title}}",
|
||
"termsOfService": "http://swagger.io/terms/",
|
||
"contact": {
|
||
"name": "API Support",
|
||
"url": "http://www.swagger.io/support",
|
||
"email": "support@swagger.io"
|
||
},
|
||
"license": {
|
||
"name": "Apache 2.0",
|
||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||
},
|
||
"version": "{{.Version}}"
|
||
},
|
||
"host": "{{.Host}}",
|
||
"basePath": "{{.BasePath}}",
|
||
"paths": {
|
||
"/ping": {
|
||
"get": {
|
||
"description": "检查服务器是否正常运行",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"系统"
|
||
],
|
||
"summary": "健康检查",
|
||
"responses": {
|
||
"200": {
|
||
"description": "OK",
|
||
"schema": {
|
||
"allOf": [
|
||
{
|
||
"$ref": "#/definitions/handler.Response"
|
||
},
|
||
{
|
||
"type": "object",
|
||
"properties": {
|
||
"data": {
|
||
"type": "object",
|
||
"properties": {
|
||
"time": {
|
||
"type": "string"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/test/401": {
|
||
"get": {
|
||
"description": "模拟返回 HTTP 401 未授权错误",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"测试"
|
||
],
|
||
"summary": "测试 401 错误",
|
||
"responses": {
|
||
"401": {
|
||
"description": "Unauthorized",
|
||
"schema": {
|
||
"$ref": "#/definitions/handler.Response"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/test/403": {
|
||
"get": {
|
||
"description": "模拟返回 HTTP 403 禁止访问错误",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"测试"
|
||
],
|
||
"summary": "测试 403 错误",
|
||
"responses": {
|
||
"403": {
|
||
"description": "Forbidden",
|
||
"schema": {
|
||
"$ref": "#/definitions/handler.Response"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/test/500": {
|
||
"get": {
|
||
"description": "模拟返回 HTTP 500 服务器内部错误",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"测试"
|
||
],
|
||
"summary": "测试 500 错误",
|
||
"responses": {
|
||
"500": {
|
||
"description": "Internal Server Error",
|
||
"schema": {
|
||
"$ref": "#/definitions/handler.Response"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/test/error/{code}": {
|
||
"get": {
|
||
"description": "根据错误码返回对应的业务错误响应",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"测试"
|
||
],
|
||
"summary": "测试业务错误响应",
|
||
"parameters": [
|
||
{
|
||
"type": "integer",
|
||
"description": "业务错误码 (10001-10099: 认证相关, 20001-20099: 任务相关)",
|
||
"name": "code",
|
||
"in": "path",
|
||
"required": true
|
||
}
|
||
],
|
||
"responses": {
|
||
"200": {
|
||
"description": "OK",
|
||
"schema": {
|
||
"allOf": [
|
||
{
|
||
"$ref": "#/definitions/handler.Response"
|
||
},
|
||
{
|
||
"type": "object",
|
||
"properties": {
|
||
"details": {
|
||
"type": "string"
|
||
}
|
||
}
|
||
}
|
||
]
|
||
}
|
||
},
|
||
"400": {
|
||
"description": "Bad Request",
|
||
"schema": {
|
||
"$ref": "#/definitions/handler.Response"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/test/paginated": {
|
||
"get": {
|
||
"description": "测试返回分页数据的统一响应格式",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"测试"
|
||
],
|
||
"summary": "测试分页响应",
|
||
"responses": {
|
||
"200": {
|
||
"description": "OK",
|
||
"schema": {
|
||
"allOf": [
|
||
{
|
||
"$ref": "#/definitions/handler.Response"
|
||
},
|
||
{
|
||
"type": "object",
|
||
"properties": {
|
||
"data": {
|
||
"allOf": [
|
||
{
|
||
"$ref": "#/definitions/handler.PaginatedData"
|
||
},
|
||
{
|
||
"type": "object",
|
||
"properties": {
|
||
"items": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/test/success": {
|
||
"get": {
|
||
"description": "测试返回成功的统一响应格式",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"测试"
|
||
],
|
||
"summary": "测试成功响应",
|
||
"responses": {
|
||
"200": {
|
||
"description": "OK",
|
||
"schema": {
|
||
"allOf": [
|
||
{
|
||
"$ref": "#/definitions/handler.Response"
|
||
},
|
||
{
|
||
"type": "object",
|
||
"properties": {
|
||
"data": {
|
||
"type": "object",
|
||
"properties": {
|
||
"role": {
|
||
"type": "string"
|
||
},
|
||
"username": {
|
||
"type": "string"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"/test/timeout": {
|
||
"get": {
|
||
"description": "模拟请求超时(15秒延迟,超过前端 10s timeout)",
|
||
"consumes": [
|
||
"application/json"
|
||
],
|
||
"produces": [
|
||
"application/json"
|
||
],
|
||
"tags": [
|
||
"测试"
|
||
],
|
||
"summary": "测试超时响应",
|
||
"responses": {
|
||
"200": {
|
||
"description": "OK",
|
||
"schema": {
|
||
"$ref": "#/definitions/handler.Response"
|
||
}
|
||
},
|
||
"408": {
|
||
"description": "Request Timeout",
|
||
"schema": {
|
||
"$ref": "#/definitions/handler.Response"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"definitions": {
|
||
"handler.PaginatedData": {
|
||
"type": "object",
|
||
"properties": {
|
||
"items": {},
|
||
"total": {
|
||
"type": "integer"
|
||
}
|
||
}
|
||
},
|
||
"handler.Response": {
|
||
"type": "object",
|
||
"properties": {
|
||
"code": {
|
||
"description": "业务错误码,0 表示成功",
|
||
"type": "integer"
|
||
},
|
||
"data": {
|
||
"description": "响应数据,成功时返回"
|
||
},
|
||
"details": {
|
||
"description": "错误详情,失败时返回",
|
||
"type": "string"
|
||
},
|
||
"message": {
|
||
"description": "响应消息",
|
||
"type": "string"
|
||
}
|
||
}
|
||
}
|
||
},
|
||
"securityDefinitions": {
|
||
"BearerAuth": {
|
||
"description": "请输入 Bearer Token(例如:Bearer xxx)",
|
||
"type": "apiKey",
|
||
"name": "Authorization",
|
||
"in": "header"
|
||
}
|
||
}
|
||
}`
|
||
|
||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||
var SwaggerInfo = &swag.Spec{
|
||
Version: "1.0",
|
||
Host: "",
|
||
BasePath: "/api/v1",
|
||
Schemes: []string{},
|
||
Title: "xinfra API",
|
||
Description: "xinfra 平台后端 API 文档",
|
||
InfoInstanceName: "swagger",
|
||
SwaggerTemplate: docTemplate,
|
||
LeftDelim: "{{",
|
||
RightDelim: "}}",
|
||
}
|
||
|
||
func init() {
|
||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||
}
|