servers

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attachment added in v0.2.4

func Attachment(c *gin.Context, filename string, data []byte)

Attachment attachment application/octet-stream;charset=utf-8

func JSON

func JSON(c *gin.Context, httpCode int, opts ...Option)

JSON 标准http status code应答

func JSONCustom

func JSONCustom(c *gin.Context, code Code, opts ...Option)

JSONCustom http.StatusBadRequest式应答,自定义code码应答,一般给前端显示使用

func JSONDetail

func JSONDetail(c *gin.Context, err error, opts ...Option)

JSONDetail http.StatusBadRequest式应答,detail为err的stringer

Types

type Code

type Code interface {
	fmt.Stringer
	Value() int
}

Code custom code interface

type Option added in v0.3.3

type Option func(r *Response)

Option option

func WithCode added in v0.3.3

func WithCode(code int) Option

WithCode code

func WithData added in v0.3.3

func WithData(data interface{}) Option

WithData data

func WithDetail added in v0.3.3

func WithDetail(detail string) Option

WithDetail detail 开发调试使用

func WithError added in v0.3.3

func WithError(err error) Option

WithError err detail为err的stringer

func WithICode added in v0.3.3

func WithICode(code Code) Option

WithICode Code interface 使应答修改code和msg,用于显示

func WithMsg added in v0.3.3

func WithMsg(msg string) Option

WithMsg message

type Response

type Response struct {
	Code   int         `json:"code"`             // 码
	Msg    string      `json:"msg,omitempty"`    // 信息
	Detail string      `json:"detail,omitempty"` // 错误携带的信息, 用于开发者调试
	Data   interface{} `json:"data"`             // 数据域
}

Response 信息回复基本格式

Jump to

Keyboard shortcuts

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