response

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 6 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 int32) *BaseResponse

func (*BaseResponse) SetTotal

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

type Meta

type Meta struct {
	*web.Paging `json:",inline"`
	Total       int32             `json:"total"`
	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 int32) *Meta

func (*Meta) SetTotal

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

type Response

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

func NewResponseFromCode

func NewResponseFromCode(code errors.ErrorCode) *Response

func NewResponseFromPb

func NewResponseFromPb(err *errors.Error) *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(paging *web.Paging) SetFunc

func SetTotal

func SetTotal(total int32) SetFunc

Jump to

Keyboard shortcuts

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