middleware

package
v0.0.0-...-2828958 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GinRecovery

func GinRecovery(stack bool) gin.HandlerFunc

GinRecovery recover掉项目可能出现的panic

func RequestInLog

func RequestInLog(c *gin.Context)

RequestInLog 请求进来的日志

func RequestLog

func RequestLog() gin.HandlerFunc

RequestLog 请求日志中间件

func RequestOutLog

func RequestOutLog(c *gin.Context)

RequestOutLog 请求返回是的日志

func ResponseError

func ResponseError(c *gin.Context, code ResponseCode, err error)

ResponseError 错误时返回

func ResponseSuccess

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

ResponseSuccess 成功时返回

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 以上为用户自定义码

func (ResponseCode) Msg

func (c ResponseCode) Msg() string

Msg 获取状态码对应的提示信息

Jump to

Keyboard shortcuts

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