将状态码改成自定义码

This commit is contained in:
2025-09-14 13:23:16 +08:00
parent b0ce191aff
commit b3322fe367
4 changed files with 52 additions and 40 deletions

View File

@@ -7,6 +7,23 @@ import (
"github.com/gin-gonic/gin"
)
// --- 业务状态码 ---
const (
// 成功状态码 (2000-2999)
CodeSuccess = 2000 // 操作成功
CodeCreated = 2001 // 创建成功
// 客户端错误状态码 (4000-4999)
CodeBadRequest = 4000 // 请求参数错误
CodeUnauthorized = 4001 // 未授权
CodeNotFound = 4004 // 资源未找到
CodeConflict = 4009 // 资源冲突
// 服务器错误状态码 (5000-5999)
CodeInternalError = 5000 // 服务器内部错误
CodeServiceUnavailable = 5003 // 服务不可用
)
// --- 通用响应结构 ---
// Response 定义统一的API响应结构体