gin_helper

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SUCCESS           = 200
	InvalidParams     = 400
	Unknown           = 0000
	ERROR             = 500
	ErrorTokenEmpty   = 4002
	ErrorTokenInvalid = 4003
	ErrorTokenExpire  = 4004
	ErrorUserNotExist = 4005
	TooManyRequests   = 4006
)

Variables

View Source
var MsgFlags = map[int]string{
	SUCCESS:           "ok",
	ERROR:             "服务器出错",
	Unknown:           "未知",
	TooManyRequests:   "请求太多,稍后再试",
	InvalidParams:     "请求参数错误",
	ErrorTokenEmpty:   "用户token为空",
	ErrorTokenInvalid: "用户token无效",
	ErrorTokenExpire:  "用户token过期",
	ErrorUserNotExist: "用户不存在",
}

Functions

func BindAndValid

func BindAndValid(c *gin.Context, form interface{}) error

func CheckUserToken

func CheckUserToken() gin.HandlerFunc

func Cors

func Cors() gin.HandlerFunc

func GenerateToken

func GenerateToken(username string, uid int) (string, error)

func GetMsg

func GetMsg(code int) string

func GetRequestId

func GetRequestId(ctx *gin.Context) (requestId string)

func JsonResponse

func JsonResponse(ctx *gin.Context, httpCode, retCode int, data interface{})

func Metadata

func Metadata(debug bool) gin.HandlerFunc

func ProtoBufResponse

func ProtoBufResponse(ctx *gin.Context, httpCode int, data interface{})

func RateLimit

func RateLimit(maxConcurrent int) gin.HandlerFunc

Types

type Claims

type Claims struct {
	UserName string `json:"user_name"`
	Uid      int    `json:"uid"`
	jwt.StandardClaims
}

func ParseToken

func ParseToken(token string) (*Claims, error)

Jump to

Keyboard shortcuts

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