response

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorResp

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

func ErrorRespWithStatus

func ErrorRespWithStatus(c *gin.Context, httpCode int, err error)

func OK

func OK(c *gin.Context)

OK is a shortcut for c.JSON(http.StatusOK, NewResponseFromPb(responsepb.OK))

func SuccessResp

func SuccessResp(c *gin.Context, body interface{}, sf ...SetFunc)

Types

type BaseResponse

type BaseResponse struct {
	Code    int    `json:"code"`
	Reason  string `json:"reason"`
	Message string `json:"message"`
	Meta    *Meta  `json:"meta,omitempty"`
}

func (*BaseResponse) SetMsg

func (r *BaseResponse) SetMsg(msg string) *BaseResponse

func (*BaseResponse) SetPaging

func (r *BaseResponse) SetPaging(page, size int) *BaseResponse

func (*BaseResponse) SetTotal

func (r *BaseResponse) SetTotal(t int) *BaseResponse

type Meta

type Meta struct {
	Total    int               `json:"total"`
	Page     int               `json:"page"`
	PageSize int               `json:"page_size"`
	Extra    map[string]string `json:"extra,omitempty"`
}

func (*Meta) SetExtra

func (x *Meta) SetExtra(key, value string) *Meta

func (*Meta) SetExtraInt

func (x *Meta) SetExtraInt(key string, value int) *Meta

func (*Meta) SetExtraMap

func (x *Meta) SetExtraMap(m map[string]string) *Meta

func (*Meta) SetPaging

func (x *Meta) SetPaging(page, size int) *Meta

func (*Meta) SetTotal

func (x *Meta) SetTotal(total int) *Meta

type Response

type Response struct {
	*BaseResponse
	Data interface{} `json:"data,omitempty"`
}

func NewResponseFromCode

func NewResponseFromCode(code responsepb.Code) *Response

func NewResponseFromPb

func NewResponseFromPb(base *responsepb.BaseResponse) *Response

func (*Response) SetData

func (r *Response) SetData(data interface{}) *Response

func (*Response) SetMsg

func (r *Response) SetMsg(msg string) *Response

type SetFunc

type SetFunc func(resp *BaseResponse)

func SetPaging

func SetPaging(page, size int) SetFunc

func SetTotal

func SetTotal(total int) SetFunc

Jump to

Keyboard shortcuts

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