response

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: MIT Imports: 5 Imported by: 1

README

response

封装gin返回同一个格式的json数据。


使用示例

Output函数返回兼容http状态码

SuccessError统一返回状态码200,在data.code自定义状态码

所有请求统一返回json

{
  "code": 0,
  "msg": "",
  "data": {}
}
    // c是*gin.Context

    // 返回成功
    response.Success(c)
    // 返回成功,并返回数据
    response.Success(c, gin.H{"users":users})

    // 返回失败
    response.Error(c, errcode.SendEmailErr)
    // 返回失败,并返回数据
    response.Error(c,  errcode.SendEmailErr, gin.H{"user":user})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(c *gin.Context, err *errcode.Error, data ...interface{})

Error 错误

func Output

func Output(c *gin.Context, code int, msg ...interface{})

Output 根据http status code返回json数据

func Success

func Success(c *gin.Context, data ...interface{})

Success 正确

Types

type Result

type Result struct {
	Code int         `json:"code"` // 返回码
	Msg  string      `json:"msg"`  // 返回信息说明
	Data interface{} `json:"data"` // 返回数据
}

Result 输出数据格式

Jump to

Keyboard shortcuts

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