50 lines
878 B
Go
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()
|
|
}
|
|
|
|
}
|
|
}
|