高级排程
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.

62 lines
1.1 KiB

3 years ago
  1. package middleware
  2. import (
  3. "LAPP_AS/conf"
  4. "LAPP_AS/utils"
  5. "LAPP_AS/web/middleware/jwts"
  6. "github.com/kataras/iris/v12"
  7. "strings"
  8. )
  9. type Middleware struct {
  10. }
  11. func ServeHTTP(ctx iris.Context) {
  12. path := ctx.Path()
  13. // 过滤静态资源、login接口、首页等...不需要验证
  14. if checkURL(path) || strings.Contains(path, "/public") {
  15. ctx.Next()
  16. return
  17. }
  18. // jwt token拦截
  19. if !jwts.Serve(ctx) {
  20. return
  21. }
  22. // 系统菜单不进行权限拦截
  23. publicRutes := conf.AppConfig.PublicRute
  24. res := utils.IsContain(publicRutes,path)
  25. if !res {
  26. // casbin权限拦截
  27. //ok := casbins.CheckPermissions(ctx)
  28. //if !ok {
  29. // return
  30. //}
  31. }
  32. //if !strings.Contains(path, "/sysMenu") {
  33. // // casbin权限拦截
  34. // ok := casbins.CheckPermissions(ctx)
  35. // if !ok {
  36. // return
  37. // }
  38. //}
  39. // Pass to real API
  40. ctx.Next()
  41. }
  42. /**
  43. return
  44. true:则跳过不需验证如登录接口等...
  45. false:需要进一步验证
  46. */
  47. func checkURL(reqPath string) bool {
  48. //过滤
  49. for _, v := range conf.AppConfig.Other.IgnoreURLs {
  50. if reqPath == v {
  51. return true
  52. }
  53. }
  54. return false
  55. }