routes.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * @description: 路由配置
  3. * @Author: CP
  4. * @Date: 2020-08-23 21:32:54
  5. * @FilePath: \construction_management\web\routes\routes.go
  6. */
  7. package routes
  8. import (
  9. "github.com/kataras/iris/v12/mvc"
  10. "go.mod/bootstrap"
  11. "go.mod/services"
  12. "go.mod/web/api"
  13. "go.mod/web/controllers"
  14. "go.mod/web/middleware"
  15. )
  16. func Configure(b *bootstrap.Bootstrapper) {
  17. //service加载
  18. ProjectAccountService := services.NewProjectAccountService()
  19. LoginService := services.NewLoginService()
  20. ProjectService := services.NewProjectService()
  21. TreeService := services.NewTreeService()
  22. //CSRF相关
  23. b.Use(middleware.SetCsrf)
  24. //b.Party("/", protect)
  25. //protect := NewCsrf()
  26. //登录相关
  27. //login := mvc.New(b.Party("/", protect))
  28. login := mvc.New(b.Party("/"))
  29. login.Register(ProjectAccountService)
  30. login.Register(LoginService)
  31. login.Handle(new(controllers.LoginController))
  32. // todolist相关
  33. todo := mvc.New(b.Party("/todolist"))
  34. todo.Router.Use(middleware.SessionsAuth)
  35. todo.Handle(new(controllers.TodoController))
  36. // 合同管理
  37. contract := mvc.New(b.Party("/contract"))
  38. contract.Router.Use(middleware.SessionsAuth)
  39. contract.Handle(new(controllers.ContractController))
  40. // 安全巡检
  41. //用户相关
  42. account := mvc.New(b.Party("/account"))
  43. account.Register(ProjectAccountService)
  44. account.Router.Use(middleware.SessionsAuth)
  45. account.Handle(new(controllers.AccountController))
  46. // 项目相关
  47. project := mvc.New(b.Party("/project"))
  48. project.Router.Use(middleware.SessionsAuth)
  49. project.Register(TreeService)
  50. project.Register(ProjectService)
  51. project.Handle(new(controllers.ProjectController))
  52. //标段相关
  53. bidsection := mvc.New(b.Party("/bidsection"))
  54. bidsection.Register(ProjectService)
  55. bidsection.Router.Use(middleware.SessionsAuth)
  56. bidsection.Handle(new(controllers.BidsectionController))
  57. // 接口相关
  58. // 登陆接口
  59. apiLogin := mvc.New(b.Party("/api/login"))
  60. apiLogin.Register(ProjectAccountService)
  61. apiLogin.Register(LoginService)
  62. //apiLogin.Router.Use(middleware.JwtAuth().Serve)
  63. apiLogin.Handle(new(api.LoginApi))
  64. // TreeNode相关接口
  65. apiTree := mvc.New(b.Party("/api/tree"))
  66. apiTree.Register(TreeService)
  67. apiTree.Router.Use(middleware.JwtAuth().Serve)
  68. apiTree.Handle(new(api.TreeApi))
  69. // 项目相关接口
  70. apiProject := mvc.New(b.Party("/api/project"))
  71. apiProject.Register(ProjectService)
  72. apiProject.Router.Use(middleware.JwtAuth().Serve)
  73. apiProject.Handle(new(api.ProjectApi))
  74. // 项目账号相关接口
  75. apiProjectAccount := mvc.New(b.Party("/api/projectAccount"))
  76. apiProjectAccount.Register(ProjectAccountService)
  77. apiProjectAccount.Router.Use(middleware.JwtAuth().Serve)
  78. apiProjectAccount.Handle(new(api.ProjectAccountApi))
  79. }