httputils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbortFailedWithCode

func AbortFailedWithCode(c *gin.Context, code int, err error)

AbortFailedWithCode 设置错误,code 返回值并终止请求

func SetFailed

func SetFailed(c *gin.Context, r *Response, err error)

SetFailed 设置错误返回值

func SetFailedWithCode

func SetFailedWithCode(c *gin.Context, r *Response, code int, err error)

SetFailedWithCode 设置错误返回值

func SetSuccess

func SetSuccess(c *gin.Context, r *Response)

SetSuccess 设置成功返回值

Types

type Response

type Response struct {
	Code    int         `json:"code"`              // 返回的状态码
	Result  interface{} `json:"result,omitempty"`  // 正常返回时的数据,可以为任意数据结构
	Message string      `json:"message,omitempty"` // 异常返回时的错误信息
}

func NewResponse

func NewResponse() *Response

NewResponse 构造 http 返回值 SetSuccess 时会自动设置 code 为 200 SetFailed 时不需要设置状态码,SetCode 自定义状态码

func (*Response) Error

func (r *Response) Error() string

func (*Response) SetCode

func (r *Response) SetCode(c int)

func (*Response) SetMessage

func (r *Response) SetMessage(m interface{})

func (*Response) SetMessageWithCode

func (r *Response) SetMessageWithCode(m interface{}, c int)

func (*Response) String

func (r *Response) String() string

Jump to

Keyboard shortcuts

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