package middleware import ( "eta/eta_email_analysis/controller/resp" "eta/eta_email_analysis/global" "eta/eta_email_analysis/utils" "github.com/gin-gonic/gin" ) func Token() gin.HandlerFunc { return func(c *gin.Context) { token := c.Request.Header.Get("Authorization") if token == "" { token = c.DefaultQuery("authorization", "") if token == "" { token = c.DefaultQuery("Authorization", "") } } if token == "" { resp.TokenError(nil, "非法访问", "非法访问", c) c.Abort() return } if token != utils.Authorization { resp.TokenError(nil, "非法访问", "非法访问", c) c.Abort() return } c.Next() } } func InternalToken() gin.HandlerFunc { return func(c *gin.Context) { token := c.Request.Header.Get("Authorization") if token == "" { token = c.DefaultQuery("authorization", "") if token == "" { token = c.DefaultQuery("Authorization", "") } } if token == "" { resp.TokenError(nil, "非法访问", "非法访问", c) c.Abort() return } checkToken := utils.MD5(global.CONFIG.Serve.AppNameEn + global.CONFIG.Serve.Md5Key) if token != checkToken { resp.TokenError(nil, "非法访问", "非法访问", c) c.Abort() return } c.Next() } }