response

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 4 Imported by: 1 module, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort403

func Abort403(c *gin.Context, msg ...string)

Abort403 响应 403,未传参 msg 时使用默认消息

func Abort404

func Abort404(c *gin.Context, msg ...string)

Abort404 响应 404,未传参 msg 时使用默认消息

func Abort500

func Abort500(c *gin.Context, msg ...string)

Abort500 响应 500,未传参 msg 时使用默认消息

func BadRequest

func BadRequest(c *gin.Context, err error, msg ...string)

BadRequest 响应 400,传参 err 对象,未传参 msg 时使用默认消息 在解析用户请求,请求的格式或者方法不符合预期时调用

func Created

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

Created 响应 201 和带 data 键的 JSON 数据 执行『更新操作』成功后调用,例如更新话题,成功后返回已更新的话题

func CreatedJSON

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

CreatedJSON 响应 201 和 JSON 数据

func Data

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

Data 响应 200 和带 data 键的 JSON 数据 执行『更新操作』成功后调用,例如更新话题,成功后返回已更新的话题

func Error

func Error(c *gin.Context, err error, msg ...string)

Error 响应 404 或 422,未传参 msg 时使用默认消息 处理请求时出现错误 err,会附带返回 error 信息,如登录错误、找不到 ID 对应的 Model

func JSON

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

JSON 响应 200 和 JSON 数据

func Success

func Success(c *gin.Context)

Success 响应 200 和预设『操作成功!』的 JSON 数据 执行某个『没有具体返回数据』的『变更』操作成功后调用,例如删除、修改密码、修改手机号

func Unauthorized

func Unauthorized(c *gin.Context, msg ...string)

Unauthorized 响应 401,未传参 msg 时使用默认消息 登录失败、jwt 解析失败时调用

func ValidationError

func ValidationError(c *gin.Context, errors map[string][]string)

ValidationError 处理表单验证不通过的错误,返回的 JSON 示例:

{
    "errors": {
        "phone": [
            "手机号为必填项,参数名称 phone",
            "手机号长度必须为 11 位的数字"
        ]
    },
    "message": "请求验证不通过,具体请查看 errors"
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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