response

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

response

功能

用法

Documentation

Overview

Package response 提供统一的 JSON 返回结构,可以通过配置设置具体返回的 code 字段为 int 或者 string

Index

Constants

This section is empty.

Variables

View Source
var (
	CodeSuccess       = goutils.NewErrCode(success, gettext.Gettext("成功"))
	CodeFailure       = goutils.NewErrCode(failure, gettext.Gettext("失败"))
	CodeInvalidParam  = goutils.NewErrCode(invalidParam, gettext.Gettext("参数错误"))
	CodeNotFound      = goutils.NewErrCode(notFound, gettext.Gettext("未找到"))
	CodeInternalError = goutils.NewErrCode(unknownError, gettext.Gettext("未知错误"))
)

错误码对象定义

Functions

func ErrJSON

func ErrJSON(c *gin.Context, err error, extraMsgs ...interface{})

ErrJSON 返回 HTTP 状态码为 200 的统一失败结构

func IsInvalidParamError

func IsInvalidParamError(err error) bool

IsInvalidParamError 判断错误信息中是否包含:参数错误

func JSON

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

JSON 返回 HTTP 状态码为 200 的统一成功结构

func Respond

func Respond(c *gin.Context, status int, data interface{}, errcode error, extraMsgs ...interface{})

Respond encapsulates c.JSON debug mode respond indented json

Types

type Response

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

Response 统一的返回结构定义

Jump to

Keyboard shortcuts

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