render

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 6 Imported by: 0

README

render

gin返回的封装插件,这个插件已丢弃,被github.com/zhufuyi/pkg/gin/response代替。


安装

go get -u github.com/zhufuyi/pkg/gin/response


使用示例

Respond函数返回兼容http状态码

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

所有请求统一返回json

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

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

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

Documentation

Overview

nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error deprecated

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

Error 错误

Deprecated: this function simply calls response.Error.

func Respond deprecated

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

Respond 根据http status code返回json数据

Deprecated: this function simply calls response.Output.

func Success deprecated

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

Success 正确

Deprecated: this function simply calls response.Success.

Types

type JSONResponse

type JSONResponse struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

JSONResponse 输出格式

Jump to

Keyboard shortcuts

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