Documentation ¶
Index ¶
- Constants
- Variables
- type IdReq
- type IdsReq
- type PageAnyMetaResp
- type PageAnyResp
- type PageData
- type PageInfo
- type PageMetaResp
- type PageResp
- type Resp
- func Fail(code StatusCode, msg string) *Resp
- func FailCode(code StatusCode) *Resp
- func FailMsg(msg string) *Resp
- func New(code StatusCode, msg string) *Resp
- func NewCode(code StatusCode) *Resp
- func Success() *Resp
- func SuccessCreate() *Resp
- func SuccessDelete() *Resp
- func SuccessMsg(msg string) *Resp
- func SuccessUpdate() *Resp
- type RespData
- func FailCodeDetails[T any](code StatusCode, data T) *RespData[T]
- func FailDetails[T any](code StatusCode, msg string, data T) *RespData[T]
- func FailMsgDetails[T any](msg string, data T) *RespData[T]
- func NewWithData[T any](code StatusCode, msg string, data T) *RespData[T]
- func SuccessData[T any](data T) *RespData[T]
- func SuccessMsgData[T any](msg string, data T) *RespData[T]
- func SuccessRead[T any](data T) *RespData[T]
- type StatusCode
Constants ¶
View Source
const ( FailParamParse = "参数解析失败" FailParamValid = "参数校验不通过" FailIDNotNil = "ID值不能为空" FailRecordNotFound = "数据不存在" OKCreate = "创建成功" OkRead = "获取成功" OKUpdate = "更新成功" OKDelete = "删除成功" OkSave = "保存成功" FailCreate = "创建失败" FailRead = "获取失败" FailUpdate = "更新失败" FailDelete = "删除失败" FailSave = "保存失败" OKUpload = "上传成功" OkDownload = "下载成功" FailUpload = "上传失败" FailDownload = "下载失败" FailFileRead = "文件读取失败" FailFileParse = "文件解析失败" FailFileFormat = "文件格式不支持" )
Variables ¶
View Source
var Status = map[StatusCode]string{
0: "操作成功",
4000: "参数解析失败",
4001: "参数校验不通过",
4010: "无效的Token",
4011: "Token缺失",
4030: "权限不足",
4050: "请求方法不支持",
4100: "值不存在",
5000: "系统内部错误",
5001: "操作失败",
}
Status {code, msg}
Functions ¶
This section is empty.
Types ¶
type IdReq ¶ added in v0.0.3
type IdReq struct {
ID string `json:"id" form:"id" binding:"required"`
}
type PageAnyMetaResp ¶ added in v0.0.5
type PageAnyMetaResp[M any] struct { PageInfo Total int `json:"total"` // 总页数 List any `json:"list"` // 列表数据 Meta M `json:"meta"` }
PageAnyMetaResp 分页数据响应体 (携带额外数据) M 非列表数据的数据类型
func NewPageAnyMeta ¶ added in v0.0.5
func NewPageAnyMeta[M any](list any, total int, page, pageSize uint, meta M) *PageAnyMetaResp[M]
type PageAnyResp ¶ added in v0.0.5
PageAnyResp 分页数据响应体 使用场景:匿名结构体返回的时候
func NewPageAny ¶ added in v0.0.5
func NewPageAny(list any, total int, page, pageSize uint) *PageAnyResp
type PageMetaResp ¶
PageMetaResp 分页数据响应体 (携带额外数据) T 列表每一项的数据类型 M 非列表数据的数据类型
func NewPageMeta ¶
func NewPageMeta[T any, M any](list []T, total int, page, pageSize uint, meta M) *PageMetaResp[T, M]
NewPageMeta 分页数据组装-携带非列表数据
page 当前数据是第几页 total 总的条数 pageSize 每一页多少条数据 meta 非列表数据
type Resp ¶ added in v0.0.6
type Resp struct { Code StatusCode `json:"code"` Msg string `json:"msg"` }
type RespData ¶ added in v0.0.6
RespData 响应结构体 T 返回数据的数据类型
func FailCodeDetails ¶ added in v0.0.6
func FailCodeDetails[T any](code StatusCode, data T) *RespData[T]
FailCodeDetails 从 statusCode 定义错误提示信息,并带详情信息
func FailDetails ¶ added in v0.0.6
func FailDetails[T any](code StatusCode, msg string, data T) *RespData[T]
FailDetails 自定义 code 和错误提示信息,错误细节
func FailMsgDetails ¶ added in v0.0.6
FailMsgDetails 自定义错误提示信息和错误细节,默认 code = 5000
func NewWithData ¶ added in v0.0.6
func NewWithData[T any](code StatusCode, msg string, data T) *RespData[T]
NewWithData 自定义 code 和提示信息,并携带数据
func SuccessData ¶ added in v0.0.6
SuccessData 使用默认提示消息,并携带数据
func SuccessMsgData ¶ added in v0.0.6
SuccessMsgData 自定义提示消息,并携带数据
func SuccessRead ¶ added in v0.0.6
type StatusCode ¶
type StatusCode uint16
StatusCode 响应状态
const ( Ok StatusCode = 0 ParameterIllegal StatusCode = 4000 ParameterInvalid StatusCode = 4001 TokenInvalid StatusCode = 4010 TokenMission StatusCode = 4011 Forbidden StatusCode = 4030 Gone StatusCode = 4100 Internal StatusCode = 5000 )
Click to show internal directories.
Click to hide internal directories.