go-wxhelper/router/middleware/request.go
2024-01-19 12:06:30 +08:00

34 lines
686 B
Go

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()
}
}