liuhaijun e94826ce29 add server
Change-Id: I0760f17f6a01c0121b59fcbfafc666032dbc30af
2024-09-19 09:44:15 +00:00

50 lines
878 B
Go

package middleware
import (
"github.com/gin-gonic/gin"
"github.com/golang/glog"
"regexp"
)
func AuthorizationHandler() gin.HandlerFunc {
return func(c *gin.Context) {
match, _ := regexp.MatchString("/healthz", c.Request.RequestURI)
if match {
c.Next()
return
}
match, _ = regexp.MatchString("/run", c.Request.RequestURI)
if match {
c.Next()
return
}
match, _ = regexp.MatchString("/login", c.Request.RequestURI)
if match {
c.Next()
return
}
match, _ = regexp.MatchString("/api/v1/socket/*", c.Request.RequestURI)
if match {
c.Next()
return
}
match, _ = regexp.MatchString("/api/v1/*", c.Request.RequestURI)
if match {
_, exist := c.Get(LoginUserKey)
if !exist {
glog.Fatal("Authorization middleware should work together with Authentication middleware")
c.Next()
return
}
c.Next()
}
}
}