You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

63 lines
1.2 KiB

package middleware
import (
"github.com/kataras/iris/v12"
"leit.com/LAPP_GAAS_GFrame/conf"
"leit.com/LAPP_GAAS_GFrame/utils"
"leit.com/LAPP_GAAS_GFrame/web/middleware/casbins"
"leit.com/LAPP_GAAS_GFrame/web/middleware/jwts"
"strings"
)
type Middleware struct {
}
func ServeHTTP(ctx iris.Context) {
path := ctx.Path()
// 过滤静态资源、login接口、首页等...不需要验证
if checkURL(path) || strings.Contains(path, "/public") {
ctx.Next()
return
}
// jwt token拦截
if !jwts.Serve(ctx) {
return
}
// 系统菜单不进行权限拦截
publicRutes := conf.AppConfig.PublicRute
res := utils.IsContain(publicRutes,path)
if !res {
// casbin权限拦截
ok := casbins.CheckPermissions(ctx)
if !ok {
return
}
}
//if !strings.Contains(path, "/sysMenu") {
// // casbin权限拦截
// ok := casbins.CheckPermissions(ctx)
// if !ok {
// return
// }
//}
// Pass to real API
ctx.Next()
}
/**
return
true:则跳过不需验证,如登录接口等...
false:需要进一步验证
*/
func checkURL(reqPath string) bool {
//过滤
for _, v := range conf.AppConfig.Other.IgnoreURLs {
if reqPath == v {
return true
}
}
return false
}