package middleware import ( "fmt" "github.com/gin-gonic/gin" "net/http" "wechat-robot/pkg/response" ) // NoMethodHandler // @description: 405错误处理 // @return gin.HandlerFunc func NoMethodHandler() gin.HandlerFunc { return func(ctx *gin.Context) { response.New(ctx). SetCode(http.StatusMethodNotAllowed). SetMsg(fmt.Sprintf("不支持%v请求", ctx.Request.Method)). Fail() ctx.Abort() } } // NoRouteHandler // @description: 404错误处理 // @return gin.HandlerFunc func NoRouteHandler() gin.HandlerFunc { return func(ctx *gin.Context) { response.New(ctx).SetCode(http.StatusNotFound). SetMsg("请求接口不存在"). Result() ctx.Abort() } }