gin_utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Gin request 请求参数

Gin response 响应参数

Index

Constants

This section is empty.

Variables

View Source
var (
	JSONMarshal       = json.Marshal
	JSONUnmarshal     = json.Unmarshal
	JSONMarshalIndent = json.MarshalIndent
	JSONNewDecoder    = json.NewDecoder
	JSONNewEncoder    = json.NewEncoder
)

定义JSON操作

Functions

func JSONMarshalToString

func JSONMarshalToString(v interface{}) string

JSONMarshalToString JSON编码为字符串

func ParseJSON

func ParseJSON(c *gin.Context, obj interface{}) error

ParseJSON 获取json 和解析参数

func ResponseErrorBody

func ResponseErrorBody(c *gin.Context, msg interface{})

ResponseErrorBody 请求错误

func ResponseSuccessBody

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

ResponseSuccessBody 请求成功

func ResponseWarningBody

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

ResponseWarningBody 警告

Types

type CodeType

type CodeType int
const (
	// 成功
	RetSuccess CodeType = 0

	// 路径错误
	RetError CodeType = 1

	// 部分错误
	RetWarning CodeType = -1
)

type RateKeyFunc

type RateKeyFunc func(ctx *gin.Context) (string, error)

type RateLimiterMiddleware

type RateLimiterMiddleware struct {
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(interval time.Duration, capacity int64, keyGen RateKeyFunc) *RateLimiterMiddleware

func (*RateLimiterMiddleware) Middleware

func (r *RateLimiterMiddleware) Middleware() gin.HandlerFunc

type ResponseError

type ResponseError struct {
	Code CodeType    `json:"code"`
	Msg  interface{} `json:"msg"`
	Data interface{} `json:"data"`
}

ResponseError 定义响应错误

Jump to

Keyboard shortcuts

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