xhttp

package
v0.0.0-...-663b367 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(c *gin.Context, err error)

Error 错误响应

func Success

func Success(c *gin.Context, data interface{})

Success 成功响应

Types

type APIResponse

type APIResponse struct {
	Code    int         `json:"code"`               // 业务编码
	Status  bool        `json:"status"`             // 请求是否成功
	Message string      `json:"message,omitempty"`  // 错误描述
	Current int         `json:"current,omitempty"`  // 当前页码
	Size    int         `json:"size,omitempty"`     // 当前页数量
	PerPage int         `json:"per_page,omitempty"` // 每页数量
	Total   int64       `json:"total,omitempty"`    // 总数量
	Data    interface{} `json:"data,omitempty"`     // 数据
	Order   string      `json:"order,omitempty"`    // 排序字段
	TraceID string      `json:"trace_id,omitempty"` // 追踪ID
}

APIResponse 标准响应结构

func NewResponse

func NewResponse(err *xerror.Error) *APIResponse

func NewResponseData

func NewResponseData(err *xerror.Error, data interface{}) *APIResponse

func NewResponseMessage

func NewResponseMessage(err *xerror.Error, message string) *APIResponse

func (*APIResponse) ToString

func (res *APIResponse) ToString() string

ToString 返回 JSON 格式的错误详情

func (*APIResponse) WithCurrent

func (res *APIResponse) WithCurrent(current int) *APIResponse

func (*APIResponse) WithData

func (res *APIResponse) WithData(data interface{}) *APIResponse

func (*APIResponse) WithMessage

func (res *APIResponse) WithMessage(msg string) *APIResponse

func (*APIResponse) WithPerPage

func (res *APIResponse) WithPerPage(perPage int) *APIResponse

func (*APIResponse) WithSize

func (res *APIResponse) WithSize(size int) *APIResponse

func (*APIResponse) WithTotal

func (res *APIResponse) WithTotal(total int64) *APIResponse

func (*APIResponse) WithTraceID

func (res *APIResponse) WithTraceID(traceID string) *APIResponse

type PageReq

type PageReq struct {
	Current int    `json:"current" form:"current" binding:"omitempty,min=1" default:"1"` // 当前页
	Size    int    `json:"size" form:"size" binding:"omitempty,min=1" default:"10"`      // 每页大小
	Order   string `json:"order" form:"order" binding:"omitempty" default:"id"`          // 排序字段
}

func (PageReq) GetCurrent

func (p PageReq) GetCurrent() int

func (PageReq) GetLimit

func (p PageReq) GetLimit() int

func (PageReq) GetOffset

func (p PageReq) GetOffset() int

func (PageReq) GetOrder

func (p PageReq) GetOrder() string

func (PageReq) GetSize

func (p PageReq) GetSize() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL