response

package
v1.1.18 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 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 returns the standard HTTP status code and message, parameter err is errcode.Error

func Output

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

Output return standard HTTP status codes and message, parameter code is 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