http_response

package
v0.0.0-...-0ff87c8 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ServerErr = NewErrResponse(500, errors.New("服务器错误"), nil)
	ClientErr = NewErrResponse(400, errors.New("客户端错误"), nil)
	MysqlErr  = NewErrResponse(500, errors.New("数据库错误"), nil)
	RedisErr  = NewErrResponse(500, errors.New("redis错误"), nil)
	NoData    = NewErrResponse(404, errors.New("没有数据"), nil)
)
View Source
var (
	ServerErrCode = 500
	ClientErrCode = 400
	MysqlErrCode  = 500
	RedisErrCode  = 500
	NoDataCode    = 404
)

Functions

func GinErrResp

func GinErrResp(ctx context.Context, c *gin.Context, err error)

func GinNewResponse

func GinNewResponse[T struct{} | map[string]any](ctx context.Context, c *gin.Context, code int, data T)

func GinSuccessResp

func GinSuccessResp(ctx context.Context, c *gin.Context, message string, data interface{})

func HertzErrResp

func HertzErrResp(ctx context.Context, c *app.RequestContext, err error)

func HertzNewResponse

func HertzNewResponse[T Response](ctx context.Context, c *app.RequestContext, x T)

func HertzSuccessResp

func HertzSuccessResp(ctx context.Context, c *app.RequestContext, message string, data interface{})

Types

type Page

type Page struct {
	Data    interface{} `json:"data,omitempty"`
	Total   int64       `json:"total,omitempty"`
	HasNext bool        `json:"has_next,omitempty"`
	HasPrev bool        `json:"has_prev,omitempty"`
}

func NewPageData

func NewPageData(page int64, perPageSize int64, total int64, data interface{}) *Page

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	Success bool        `json:"success"`
}

Response 返回参数

func NewErrResponse

func NewErrResponse(code int, err error, data interface{}) *Response

NewErrResponse 失败返回

func NewSuccessResponse

func NewSuccessResponse(code int, message string, data interface{}) *Response

NewSuccessResponse 成功返回

Jump to

Keyboard shortcuts

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