liuxiaolong
2019-10-22 449c4b9a06eb4b2e8de37e4ac13c3dd8d424d43d
middlewares/auth/auth.go
@@ -4,8 +4,8 @@
   "github.com/gin-gonic/gin"
   "net/http"
   "strings"
   "webserver/extend/config"
   "webserver/extend/logger"
   "webserver/extend/code"
   "webserver/extend/util"
)
const (
@@ -28,28 +28,14 @@
func AuthHandler() gin.HandlerFunc {
   return func(c *gin.Context) {
      urlPath := c.Request.URL.Path
      if strings.Contains(urlPath,"/data/api-v") && !strings.Contains(urlPath,"login"){
         //jwtDriver :=NewJwtAuthDriver()
         //if !jwtDriver.Check(c) {
         //   util.ResponseFormat(c,code.TokenNotFound,"尚未登录,请登录")
         //   c.Abort()
         //}
         c.Next()
      } else if strings.HasPrefix(urlPath,"/httpImage") {
         imgUrl := config.Server.ImageUrl
         idx := strings.Index(urlPath, ":")
         tmpPath := urlPath
         if idx >-1 {//路径中包含有端口,取端口以后路径
            tmpPath = urlPath[idx:]
            imgIndx := strings.Index(imgUrl, ":")
            if imgIndx > -1 {
               imgUrl = imgUrl[:imgIndx-1]
            }
         jwtDriver :=NewJwtAuthDriver()
         if !jwtDriver.Check(c) {
            util.ResponseFormat(c,code.TokenNotFound,"尚未登录,请登录")
            c.Abort()
         }
         logger.Debug("imgUrl+tmpPath:", imgUrl+tmpPath)
         c.Header("Access-Control-Allow-Origin","*")
         c.Redirect(http.StatusMovedPermanently, imgUrl+tmpPath)
         return
         c.Next()
      } else {
         c.Next()
      }