package middleware import ( "Lee-WineList/core" "github.com/gin-gonic/gin" "net/http" ) type request struct{} // Request Open func Request() *request { return &request{} } // NotInternalRequest 检查是否是内部调用 func (request) NotInternalRequest() gin.HandlerFunc { return func(ctx *gin.Context) { // 取出来源 from := ctx.Request.Header.Get("X-Request-From") if from != "internal" { // 如果请求不是内部请求,直接返回请求不合法 core.R(ctx).FailWithMessageAndCode("请求不合法", http.StatusBadRequest) ctx.Abort() return } ctx.Next() } }