You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
606 B
Go

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