这是全局判断,所有路由都需要判断token参数
type TokenCheck struct {}func NewTokenCheck() *TokenCheck {return &TokenCheck{}}func(this *TokenCheck) OnRequest(ctx *gin.Context) error{if ctx.Query("token")==""{goft.Throw("token requred",503,ctx)}return nil}func(this *TokenCheck) OnResponse(result interface{}) (interface{}, error){return result,nil}
视频演示地址:
中间件的使用(1):判断必要参数
