liuxiaolong
2019-08-16 cfeba2dea02c1de54cde6c95f2a3f46c121d34aa
middlewares/auth/auth.go
@@ -3,6 +3,7 @@
import (
   "github.com/gin-gonic/gin"
   "net/http"
   "regexp"
   "strings"
   "webserver/extend/config"
   "webserver/extend/logger"
@@ -28,6 +29,7 @@
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) {
@@ -36,14 +38,25 @@
         //}
         c.Next()
      } else if strings.HasPrefix(urlPath,"/httpImage") {
         host := c.Request.Host
         logger.Debug("host:", host)
         imgUrl := config.Server.ImageUrl
         domain := config.Server.PublicDomain
         domainReg := regexp.MustCompile(``+domain+``)
         if domainReg.MatchString(host) {//域名访问
            imgUrl = domain
         }
         urlPath = strings.Replace(urlPath, "/httpImage", "", -1)
         idx := strings.Index(urlPath, ":")
         tmpPath := urlPath
         if idx >-1 {//路径中包含有端口,取端口以后路径
            tmpPath = urlPath[idx:]
            imgIndx := strings.Index(imgUrl, ":")
            imgIndx := strings.LastIndex(imgUrl, ":")
            if imgIndx > -1 {
               imgUrl = imgUrl[:imgIndx-1]
               imgUrl = imgUrl[:imgIndx]
            }
         }
         logger.Debug("imgUrl+tmpPath:", imgUrl+tmpPath)