Documentation
¶
Overview ¶
Package response 提供HTTP响应数据的数据结构定义 本文件定义了统一的响应码常量和响应消息,用于标准化API响应格式
Package response 提供HTTP响应数据的数据结构定义 本文件定义了分页查询结果的响应结构,用于返回分页数据和分页信息
Package response 提供HTTP响应数据的数据结构定义 本文件定义了统一的HTTP响应结构和便捷的响应方法,用于标准化API响应格式
Index ¶
- Variables
- func Fail(c *gin.Context)
- func FailWithDetail(c *gin.Context, message string, data any)
- func FailWithMessage(c *gin.Context, message string)
- func NoAuth(c *gin.Context, message string)
- func Ok(c *gin.Context)
- func OkWithData(c *gin.Context, data any)
- func OkWithDetail(c *gin.Context, message string, data any)
- func OkWithMessage(c *gin.Context, message string)
- func Result(c *gin.Context, code int, data any, msg string)
- type PageResult
- type Response
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // 特殊响应码 ResponseNull = responseCode{/* contains filtered or unexported fields */} // 空回复,该回复不写入到responseBody中,一般用于文件下载等特殊场景 // 成功响应码 ResponseSuccess = responseCode{/* contains filtered or unexported fields */} // 标准成功响应 // 认证相关响应码(41xxx系列) ResponseLoginNotLogin = responseCode{/* contains filtered or unexported fields */} // 用户未登录状态 ResponseLoginButUnAuth = responseCode{/* contains filtered or unexported fields */} // 未通过双因子认证 ResponseLoginInvalid = responseCode{/* contains filtered or unexported fields */} // 登录会话已过期 ResponseAuthFailed = responseCode{/* contains filtered or unexported fields */} // 权限不足,拒绝访问 // 业务逻辑响应码(50xxx系列) ResponseFail = responseCode{/* contains filtered or unexported fields */} // 通用操作失败 ResponseParamInvalid = responseCode{/* contains filtered or unexported fields */} // 请求参数验证失败 ResponseParamTypeError = responseCode{/* contains filtered or unexported fields */} // 请求参数类型不匹配 // 系统异常响应码(90xxx系列) ResponseExceptionCommon = responseCode{/* contains filtered or unexported fields */} // 通用服务端异常 ResponseExceptionRpc = responseCode{/* contains filtered or unexported fields */} // RPC服务调用异常 ResponseExceptionUnknown = responseCode{/* contains filtered or unexported fields */} // 未分类的系统异常 )
预定义的响应码常量,按照功能模块和错误类型进行分类
Functions ¶
func FailWithDetail ¶
FailWithDetail 返回失败响应(自定义消息和数据) 该方法返回失败响应,支持自定义消息和错误详情数据 参数:
- c: Gin.Context,用于HTTP响应
- message: 自定义失败消息
- data: 错误详情数据
func FailWithMessage ¶
FailWithMessage 返回失败响应(自定义消息) 该方法返回失败响应,支持自定义失败消息 参数:
- c: Gin上下文,用于HTTP响应
- message: 自定义失败消息
func NoAuth ¶
NoAuth 返回未授权响应 该方法返回HTTP 401状态码的未授权响应,用于认证失败场景 参数:
- c: Gin上下文,用于HTTP响应
- message: 未授权原因说明
func OkWithDetail ¶
OkWithDetail 返回成功响应(自定义消息和数据) 该方法返回成功响应,支持自定义消息和业务数据 参数:
- c: Gin上下文,用于HTTP响应
- message: 自定义成功消息
- data: 业务数据
func OkWithMessage ¶
OkWithMessage 返回成功响应(自定义消息) 该方法返回成功响应,支持自定义成功消息 参数:
- c: Gin上下文,用于HTTP响应
- message: 自定义成功消息
Types ¶
type PageResult ¶
type PageResult struct {
List any `json:"list"` // 数据列表,包含当前页的数据内容,支持任意类型
Total int64 `json:"total"` // 数据总数,表示符合查询条件的所有数据条数
PageIndex int `json:"pageIndex"` // 当前页码,表示当前返回的是第几页的数据
PageSize int `json:"pageSize"` // 每页大小,表示每页包含的数据条数
}
PageResult 分页查询结果响应结构 该结构体定义了分页查询的标准响应格式,包含数据列表、总数和分页信息
Click to show internal directories.
Click to hide internal directories.