util

package
v1.2.20 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: MIT Imports: 2 Imported by: 1

README

给 gin 定制的工具函数

response

使接口的回应固定格式为

{
  "status": 0,
  "msg": "ok",
  "data": {}
}

使用

import (
  "github.com/gin-gonic/gin"
  "github.com/go-eyas/toolkit/gin/util"
)

func HelloHandler(c *gin.Context) {
  util.R(c).OK(gin.H{
    "hello": "world",
  })
  // 将会响应为
  // {
  //   "status": 0,
  //   "msg": "ok",
  //   "data": {
  //     "hello": "world",
  //   }
  // }
}

Documentation

Index

Constants

View Source
const CodeSuccess = 0
View Source
const CodeUnknowError = 99999999

Variables

This section is empty.

Functions

func R

func R(c *gin.Context) *resp

R 封装响应数据

Types

type RData

type RData struct {
	Code   int         `json:"-"` // http 状态码
	Status int         `json:"status"`
	Msg    string      `json:"msg"`
	Data   interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

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