diff --git a/.gitignore b/.gitignore index d42dadf..dd56108 100644 --- a/.gitignore +++ b/.gitignore @@ -51,5 +51,6 @@ docker-compose.override.yml # Documentation & local dev config (not tracked in repo) docs/ +!server/docs/ CLAUDE.md AGENTS.md diff --git a/Makefile b/Makefile index 0426e38..6463beb 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ help: @echo " make test - 运行测试" @echo " make docker - 构建 Docker 镜像" @echo " make clean - 清理构建产物" + @echo " make swagger - 生成 Swagger API 文档" @echo "" # 构建前后端项目 @@ -75,6 +76,12 @@ dev-down: @echo "Stopping local development environment..." docker-compose down +# Swagger 文档 +swagger: + @echo "Generating Swagger documentation..." + cd server && swag init -g cmd/server/main.go -o ./docs + @echo "Swagger docs generated at server/docs/" + # 数据库迁移 migrate-up: @echo "Running database migrations..." diff --git a/server/cmd/server/main.go b/server/cmd/server/main.go index b13787d..c672d53 100644 --- a/server/cmd/server/main.go +++ b/server/cmd/server/main.go @@ -2,15 +2,34 @@ package main import ( "fmt" - "net/http" - "strconv" - "time" "github.com/1024XEngineer/xinfra/server/internal/handler" "github.com/1024XEngineer/xinfra/server/internal/middleware" "github.com/gin-gonic/gin" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" ) +// @title xinfra API +// @version 1.0 +// @description xinfra 平台后端 API 文档 +// @termsOfService http://swagger.io/terms/ + +// @contact.name API Support +// @contact.url http://www.swagger.io/support +// @contact.email support@swagger.io + +// @license.name Apache 2.0 +// @license.url http://www.apache.org/licenses/LICENSE-2.0.html + +// @host localhost:8080 +// @BasePath /api/v1 + +// @securityDefinitions.apikey BearerAuth +// @in header +// @name Authorization +// @description 请输入 Bearer Token(例如:Bearer xxx) + func main() { r := gin.Default() @@ -18,21 +37,17 @@ func main() { r.Use(middleware.Logger()) r.Use(middleware.Recovery()) + // Swagger UI + r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.URL("/swagger/doc.json"))) + // 健康检查 - r.GET("/api/v1/ping", func(c *gin.Context) { - handler.Success(c, gin.H{"time": time.Now().Format(time.RFC3339)}) - }) + r.GET("/api/v1/ping", handler.Ping) // 测试路由组 — 用于验证统一响应格式 testGroup := r.Group("/api/v1/test") { // 成功响应 - testGroup.GET("/success", func(c *gin.Context) { - handler.Success(c, gin.H{ - "username": "testuser", - "role": "admin", - }) - }) + testGroup.GET("/success", handler.TestSuccess) // 业务错误 — 传入错误码 // GET /api/v1/test/error/10001 → LDAP 认证失败 @@ -40,47 +55,22 @@ func main() { // GET /api/v1/test/error/10003 → Token 已过期 // GET /api/v1/test/error/20001 → 任务创建失败 // GET /api/v1/test/error/20002 → 任务执行超时 - testGroup.GET("/error/:code", func(c *gin.Context) { - codeStr := c.Param("code") - code, err := strconv.Atoi(codeStr) - if err != nil { - handler.BadRequest(c, "错误码必须是数字") - return - } - details := fmt.Sprintf("这是错误码 %d 的测试响应", code) - handler.Error(c, http.StatusOK, code, details) - }) + testGroup.GET("/error/:code", handler.TestError) // HTTP 500 错误 - testGroup.GET("/500", func(c *gin.Context) { - handler.InternalError(c, "模拟服务器内部错误") - }) + testGroup.GET("/500", handler.Test500) // HTTP 401 未授权 - testGroup.GET("/401", func(c *gin.Context) { - handler.Unauthorized(c, "模拟 Token 过期") - }) + testGroup.GET("/401", handler.Test401) // HTTP 403 禁止访问 - testGroup.GET("/403", func(c *gin.Context) { - handler.Forbidden(c, "模拟无权限") - }) + testGroup.GET("/403", handler.Test403) // 模拟超时(sleep 超过前端 10s timeout) - testGroup.GET("/timeout", func(c *gin.Context) { - time.Sleep(15 * time.Second) - handler.Success(c, "这条消息不应该出现") - }) + testGroup.GET("/timeout", handler.TestTimeout) // 返回分页数据 - testGroup.GET("/paginated", func(c *gin.Context) { - items := []gin.H{ - {"id": 1, "name": "item-1"}, - {"id": 2, "name": "item-2"}, - {"id": 3, "name": "item-3"}, - } - handler.SuccessWithPaginated(c, 100, items) - }) + testGroup.GET("/paginated", handler.TestPaginated) } fmt.Println("Server starting on :8080...") diff --git a/server/docs/docs.go b/server/docs/docs.go new file mode 100644 index 0000000..c46c09a --- /dev/null +++ b/server/docs/docs.go @@ -0,0 +1,366 @@ +// 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: "localhost:8080", + BasePath: "/api/v1", + Schemes: []string{}, + Title: "xinfra API", + Description: "xinfra 平台后端 API 文档", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/server/docs/swagger.json b/server/docs/swagger.json new file mode 100644 index 0000000..6d86f6e --- /dev/null +++ b/server/docs/swagger.json @@ -0,0 +1,342 @@ +{ + "swagger": "2.0", + "info": { + "description": "xinfra 平台后端 API 文档", + "title": "xinfra API", + "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": "1.0" + }, + "host": "localhost:8080", + "basePath": "/api/v1", + "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" + } + } +} \ No newline at end of file diff --git a/server/docs/swagger.yaml b/server/docs/swagger.yaml new file mode 100644 index 0000000..a7a8ff3 --- /dev/null +++ b/server/docs/swagger.yaml @@ -0,0 +1,212 @@ +basePath: /api/v1 +definitions: + handler.PaginatedData: + properties: + items: {} + total: + type: integer + type: object + handler.Response: + properties: + code: + description: 业务错误码,0 表示成功 + type: integer + data: + description: 响应数据,成功时返回 + details: + description: 错误详情,失败时返回 + type: string + message: + description: 响应消息 + type: string + type: object +host: localhost:8080 +info: + contact: + email: support@swagger.io + name: API Support + url: http://www.swagger.io/support + description: xinfra 平台后端 API 文档 + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + termsOfService: http://swagger.io/terms/ + title: xinfra API + version: "1.0" +paths: + /ping: + get: + consumes: + - application/json + description: 检查服务器是否正常运行 + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.Response' + - properties: + data: + properties: + time: + type: string + type: object + type: object + summary: 健康检查 + tags: + - 系统 + /test/401: + get: + consumes: + - application/json + description: 模拟返回 HTTP 401 未授权错误 + produces: + - application/json + responses: + "401": + description: Unauthorized + schema: + $ref: '#/definitions/handler.Response' + summary: 测试 401 错误 + tags: + - 测试 + /test/403: + get: + consumes: + - application/json + description: 模拟返回 HTTP 403 禁止访问错误 + produces: + - application/json + responses: + "403": + description: Forbidden + schema: + $ref: '#/definitions/handler.Response' + summary: 测试 403 错误 + tags: + - 测试 + /test/500: + get: + consumes: + - application/json + description: 模拟返回 HTTP 500 服务器内部错误 + produces: + - application/json + responses: + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/handler.Response' + summary: 测试 500 错误 + tags: + - 测试 + /test/error/{code}: + get: + consumes: + - application/json + description: 根据错误码返回对应的业务错误响应 + parameters: + - description: '业务错误码 (10001-10099: 认证相关, 20001-20099: 任务相关)' + in: path + name: code + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.Response' + - properties: + details: + type: string + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/handler.Response' + summary: 测试业务错误响应 + tags: + - 测试 + /test/paginated: + get: + consumes: + - application/json + description: 测试返回分页数据的统一响应格式 + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.Response' + - properties: + data: + allOf: + - $ref: '#/definitions/handler.PaginatedData' + - properties: + items: + items: + type: object + type: array + type: object + type: object + summary: 测试分页响应 + tags: + - 测试 + /test/success: + get: + consumes: + - application/json + description: 测试返回成功的统一响应格式 + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.Response' + - properties: + data: + properties: + role: + type: string + username: + type: string + type: object + type: object + summary: 测试成功响应 + tags: + - 测试 + /test/timeout: + get: + consumes: + - application/json + description: 模拟请求超时(15秒延迟,超过前端 10s timeout) + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.Response' + "408": + description: Request Timeout + schema: + $ref: '#/definitions/handler.Response' + summary: 测试超时响应 + tags: + - 测试 +securityDefinitions: + BearerAuth: + description: 请输入 Bearer Token(例如:Bearer xxx) + in: header + name: Authorization + type: apiKey +swagger: "2.0" diff --git a/server/go.mod b/server/go.mod index 455aa12..8c40c56 100644 --- a/server/go.mod +++ b/server/go.mod @@ -1,32 +1,46 @@ module github.com/1024XEngineer/xinfra/server -go 1.21 +go 1.23.0 require github.com/gin-gonic/gin v1.9.1 require ( + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/spec v0.20.4 // indirect + github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect github.com/goccy/go-json v0.10.2 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/swaggo/files v1.0.1 // indirect + github.com/swaggo/gin-swagger v1.6.1 // indirect + github.com/swaggo/swag v1.16.3 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.9.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect + google.golang.org/protobuf v1.33.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/server/go.sum b/server/go.sum index 1a77fa1..590fc21 100644 --- a/server/go.sum +++ b/server/go.sum @@ -1,9 +1,16 @@ +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -13,6 +20,16 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -26,14 +43,25 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -41,6 +69,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -49,6 +78,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -56,31 +86,95 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.1 h1:Ri06G4gc9N4t4k8hekMigJ9zKTFSlqj/9paAQCQs7cY= +github.com/swaggo/gin-swagger v1.6.1/go.mod h1:LQ+hJStHakCWRiK/YNYtJOu4mR2FP+pxLnILT/qNiTw= +github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg= +github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/server/internal/handler/test.go b/server/internal/handler/test.go new file mode 100644 index 0000000..b6e6e5a --- /dev/null +++ b/server/internal/handler/test.go @@ -0,0 +1,125 @@ +package handler + +import ( + "fmt" + "net/http" + "strconv" + "time" + + "github.com/gin-gonic/gin" +) + +// Ping 健康检查 +// @Summary 健康检查 +// @Description 检查服务器是否正常运行 +// @Tags 系统 +// @Accept json +// @Produce json +// @Success 200 {object} Response{data=object{time=string}} +// @Router /ping [get] +func Ping(c *gin.Context) { + Success(c, gin.H{"time": time.Now().Format(time.RFC3339)}) +} + +// TestSuccess 测试成功响应 +// @Summary 测试成功响应 +// @Description 测试返回成功的统一响应格式 +// @Tags 测试 +// @Accept json +// @Produce json +// @Success 200 {object} Response{data=object{username=string,role=string}} +// @Router /test/success [get] +func TestSuccess(c *gin.Context) { + Success(c, gin.H{ + "username": "testuser", + "role": "admin", + }) +} + +// TestError 测试业务错误响应 +// @Summary 测试业务错误响应 +// @Description 根据错误码返回对应的业务错误响应 +// @Tags 测试 +// @Accept json +// @Produce json +// @Param code path int true "业务错误码 (10001-10099: 认证相关, 20001-20099: 任务相关)" +// @Success 200 {object} Response{details=string} +// @Failure 400 {object} Response +// @Router /test/error/{code} [get] +func TestError(c *gin.Context) { + codeStr := c.Param("code") + code, err := strconv.Atoi(codeStr) + if err != nil { + BadRequest(c, "错误码必须是数字") + return + } + details := fmt.Sprintf("这是错误码 %d 的测试响应", code) + Error(c, http.StatusOK, code, details) +} + +// Test500 测试 500 错误 +// @Summary 测试 500 错误 +// @Description 模拟返回 HTTP 500 服务器内部错误 +// @Tags 测试 +// @Accept json +// @Produce json +// @Success 500 {object} Response +// @Router /test/500 [get] +func Test500(c *gin.Context) { + InternalError(c, "模拟服务器内部错误") +} + +// Test401 测试 401 错误 +// @Summary 测试 401 错误 +// @Description 模拟返回 HTTP 401 未授权错误 +// @Tags 测试 +// @Accept json +// @Produce json +// @Success 401 {object} Response +// @Router /test/401 [get] +func Test401(c *gin.Context) { + Unauthorized(c, "模拟 Token 过期") +} + +// Test403 测试 403 错误 +// @Summary 测试 403 错误 +// @Description 模拟返回 HTTP 403 禁止访问错误 +// @Tags 测试 +// @Accept json +// @Produce json +// @Success 403 {object} Response +// @Router /test/403 [get] +func Test403(c *gin.Context) { +Forbidden(c, "模拟无权限") +} + +// TestTimeout 测试超时响应 +// @Summary 测试超时响应 +// @Description 模拟请求超时(15秒延迟,超过前端 10s timeout) +// @Tags 测试 +// @Accept json +// @Produce json +// @Success 200 {object} Response +// @Failure 408 {object} Response +// @Router /test/timeout [get] +func TestTimeout(c *gin.Context) { + time.Sleep(15 * time.Second) + Success(c, "这条消息不应该出现") +} + +// TestPaginated 测试分页响应 +// @Summary 测试分页响应 +// @Description 测试返回分页数据的统一响应格式 +// @Tags 测试 +// @Accept json +// @Produce json +// @Success 200 {object} Response{data=PaginatedData{items=[]object}} +// @Router /test/paginated [get] +func TestPaginated(c *gin.Context) { + items := []gin.H{ + {"id": 1, "name": "item-1"}, + {"id": 2, "name": "item-2"}, + {"id": 3, "name": "item-3"}, + } + SuccessWithPaginated(c, 100, items) +}