router.go 2.9 KB

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