Documentation ¶
Index ¶
- func GinLogger() gin.HandlerFunc
- func GinRecovery(stack bool) gin.HandlerFunc
- func IPAuthMiddleware() gin.HandlerFunc
- func JWTAuthMiddleware() func(c *gin.Context)
- func RequestInLog(c *gin.Context)
- func RequestLog() gin.HandlerFunc
- func RequestOutLog(c *gin.Context)
- func ResponseError(c *gin.Context, code ResponseCode, err error)
- func ResponseSuccess(c *gin.Context, data interface{})
- func SessionAuthMiddleware() gin.HandlerFunc
- func TranslationMiddleware() gin.HandlerFunc
- type Response
- type ResponseCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JWTAuthMiddleware ¶
JWTAuthMiddleware JWT 认证中间件 1. 查看请求头里是否带有 Token 2. 查看 Token 格式是否正确 3. 解析 Token 4. 判断与 Redis 中的 Token 是否相等(这样可以保证只能有一个客户端登录,在其他地方登录 Redis Token 刷新,之前的登录就作废了) 5. 都满足,进行下一步
func ResponseError ¶
func ResponseError(c *gin.Context, code ResponseCode, err error)
ResponseError 错误时返回
func SessionAuthMiddleware ¶
func SessionAuthMiddleware() gin.HandlerFunc
SessionAuthMiddleware session 认证中间件
func TranslationMiddleware ¶
func TranslationMiddleware() gin.HandlerFunc
TranslationMiddleware 设置 Translation
Types ¶
type Response ¶
type Response struct { ErrorCode ResponseCode `json:"errno"` // 错误码 ErrorMsg string `json:"errmsg"` // 错误信息 Data interface{} `json:"data"` // 数据信息 TraceID interface{} `json:"trace_id"` // 日志 traceID Stack interface{} `json:"stack"` // 错误堆栈信息 }
Response 响应结构体
type ResponseCode ¶
type ResponseCode int64
ResponseCode 响应状态码
const ( CodeSuccess ResponseCode = iota // success CodeUndefError // 未知的错误 CodeValidError CodeInternalError // 内部错误 CodeInvalidRequestError ResponseCode = 401 CodeCustomize ResponseCode = 1000 CodeNeedLogin ResponseCode = 1100 + iota // 用户需要登录 CodeInvalidToken // 无效 token CodeLoginElsewhere // 用户在别处登录 GROUPALL_SAVE_FLOWERROR ResponseCode = 2001 )
状态码 1000 以下为通用码,1000 以上为用户自定义码
Click to show internal directories.
Click to hide internal directories.