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.

81 lines
3.7 KiB

  1. package initialize
  2. import (
  3. //email "github.com/flipped-aurora/gva-plug-email" // 在线仓库模式
  4. "github.com/flipped-aurora/gin-vue-admin/server/plugin/email" // 本地插件仓库地址模式
  5. "github.com/flipped-aurora/gin-vue-admin/server/plugin/example_plugin"
  6. "net/http"
  7. _ "github.com/flipped-aurora/gin-vue-admin/server/docs"
  8. "github.com/flipped-aurora/gin-vue-admin/server/global"
  9. "github.com/flipped-aurora/gin-vue-admin/server/middleware"
  10. "github.com/flipped-aurora/gin-vue-admin/server/router"
  11. "github.com/gin-gonic/gin"
  12. "github.com/swaggo/gin-swagger"
  13. "github.com/swaggo/gin-swagger/swaggerFiles"
  14. )
  15. // 初始化总路由
  16. func Routers() *gin.Engine {
  17. var Router = gin.Default()
  18. Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址
  19. // Router.Use(middleware.LoadTls()) // 打开就能玩https了
  20. global.GVA_LOG.Info("use middleware logger")
  21. // 跨域
  22. //Router.Use(middleware.Cors()) // 如需跨域可以打开
  23. global.GVA_LOG.Info("use middleware cors")
  24. Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  25. global.GVA_LOG.Info("register swagger handler")
  26. // 方便统一添加路由组前缀 多服务器上线使用
  27. //获取路由组实例
  28. systemRouter := router.RouterGroupApp.System
  29. exampleRouter := router.RouterGroupApp.Example
  30. autocodeRouter := router.RouterGroupApp.Autocode
  31. PublicGroup := Router.Group("")
  32. {
  33. systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
  34. systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关
  35. }
  36. PrivateGroup := Router.Group("")
  37. PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
  38. {
  39. systemRouter.InitApiRouter(PrivateGroup) // 注册功能api路由
  40. systemRouter.InitJwtRouter(PrivateGroup) // jwt相关路由
  41. systemRouter.InitUserRouter(PrivateGroup) // 注册用户路由
  42. systemRouter.InitMenuRouter(PrivateGroup) // 注册menu路由
  43. systemRouter.InitSystemRouter(PrivateGroup) // system相关路由
  44. systemRouter.InitCasbinRouter(PrivateGroup) // 权限相关路由
  45. systemRouter.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码
  46. systemRouter.InitAuthorityRouter(PrivateGroup) // 注册角色路由
  47. systemRouter.InitSysDictionaryRouter(PrivateGroup) // 字典管理
  48. systemRouter.InitSysOperationRecordRouter(PrivateGroup) // 操作记录
  49. systemRouter.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理
  50. exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
  51. exampleRouter.InitExcelRouter(PrivateGroup) // 表格导入导出
  52. exampleRouter.InitSimpleUploaderRouter(PrivateGroup) // 断点续传(插件版)
  53. exampleRouter.InitCustomerRouter(PrivateGroup) // 客户路由
  54. // Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
  55. autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup)
  56. // Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
  57. }
  58. // 添加开放权限的插件 示例
  59. PluginInit(PublicGroup, example_plugin.ExamplePlugin)
  60. // 添加跟角色挂钩权限的插件 示例 本地示例模式于在线仓库模式注意上方的import 可以自行切换 效果相同
  61. PluginInit(PrivateGroup, email.CreateEmailPlug(
  62. global.GVA_CONFIG.Email.To,
  63. global.GVA_CONFIG.Email.From,
  64. global.GVA_CONFIG.Email.Host,
  65. global.GVA_CONFIG.Email.Secret,
  66. global.GVA_CONFIG.Email.Nickname,
  67. global.GVA_CONFIG.Email.Port,
  68. global.GVA_CONFIG.Email.IsSSL,
  69. ))
  70. global.GVA_LOG.Info("router register success")
  71. return Router
  72. }