response

package
v0.0.0-...-a518d66 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 5 Imported by: 0

README

response

The wrapper gin returns json data in the same format.


Example of use

  • Output return a compatible http status code.
  • Success and Error return a uniform status code of 200, with a custom status code in data.code

all requests return a uniform json

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

    // return success
    response.Success(c)
    // return success and return data
    response.Success(c, gin.H{"users":users})

    // return failure
    response.Error(c, errcode.SendEmailErr)
    // returns a failure and returns the data
    response.Error(c,  errcode.SendEmailErr, gin.H{"user":user})

Documentation

Overview

Package response provides wrapper gin returns json data in the same format.

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 return error

func Out

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

Out return json data by http status code, converted by errcode

func Output

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

Output return json data by http status code

func Success

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

Success return success

Types

type Result

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

Result output data format

Jump to

Keyboard shortcuts

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