router.go 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
  16. // VUE_APP_BASE_API = /
  17. // VUE_APP_BASE_PATH = http://localhost
  18. // 然后执行打包命令 npm run build。在打开下面4行注释
  19. //Router.LoadHTMLGlob("./dist/*.html") // npm打包成dist的路径
  20. //Router.Static("/favicon.ico", "./dist/favicon.ico")
  21. //Router.Static("/static", "./dist/static") // dist里面的静态资源
  22. //Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
  23. Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址
  24. // Router.Use(middleware.LoadTls()) // 打开就能玩https了
  25. global.GVA_LOG.Info("use middleware logger")
  26. // 跨域
  27. //Router.Use(middleware.Cors()) // 如需跨域可以打开
  28. global.GVA_LOG.Info("use middleware cors")
  29. Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  30. global.GVA_LOG.Info("register swagger handler")
  31. // 方便统一添加路由组前缀 多服务器上线使用
  32. //获取路由组实例
  33. systemRouter := router.RouterGroupApp.System
  34. exampleRouter := router.RouterGroupApp.Example
  35. autocodeRouter := router.RouterGroupApp.Autocode
  36. PublicGroup := Router.Group("")
  37. {
  38. systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
  39. systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关
  40. autocodeRouter.InitProblemInfoPRouter(PublicGroup) // 问题详情
  41. autocodeRouter.InitUnitPRouter(PublicGroup) // 问题详情
  42. autocodeRouter.InitContentPRouter(PublicGroup) // 内容详情
  43. systemRouter.InitWechatRouter(PublicGroup) // 微信公众号
  44. autocodeRouter.InitReadCountRouter(PublicGroup) // 查阅次数查看
  45. autocodeRouter.ProblemTypePRouter(PublicGroup) // 查阅次数查看
  46. autocodeRouter.InitOrganizationPRouter(PublicGroup) //地区查询
  47. }
  48. PrivateGroup := Router.Group("")
  49. PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
  50. {
  51. systemRouter.InitApiRouter(PrivateGroup) // 注册功能api路由
  52. systemRouter.InitJwtRouter(PrivateGroup) // jwt相关路由
  53. systemRouter.InitUserRouter(PrivateGroup) // 注册用户路由
  54. systemRouter.InitMenuRouter(PrivateGroup) // 注册menu路由
  55. systemRouter.InitSystemRouter(PrivateGroup) // system相关路由
  56. systemRouter.InitCasbinRouter(PrivateGroup) // 权限相关路由
  57. systemRouter.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码
  58. systemRouter.InitAuthorityRouter(PrivateGroup) // 注册角色路由
  59. systemRouter.InitSysDictionaryRouter(PrivateGroup) // 字典管理
  60. systemRouter.InitSysOperationRecordRouter(PrivateGroup) // 操作记录
  61. systemRouter.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理
  62. exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
  63. exampleRouter.InitExcelRouter(PrivateGroup) // 表格导入导出
  64. exampleRouter.InitCustomerRouter(PrivateGroup) // 客户路由
  65. // Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
  66. autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup)
  67. autocodeRouter.InitContentRouter(PrivateGroup)
  68. autocodeRouter.InitProblemInfoRouter(PrivateGroup)
  69. autocodeRouter.InitPlaceRouter(PrivateGroup)
  70. autocodeRouter.InitUnitRouter(PrivateGroup)
  71. autocodeRouter.InitProblemTypeRouter(PrivateGroup)
  72. autocodeRouter.InitUnitHistoryRouter(PrivateGroup)
  73. autocodeRouter.InitProblemReplyRouter(PrivateGroup)
  74. autocodeRouter.InitOrganizationRouter(PrivateGroup)
  75. autocodeRouter.InitPlaceProRouter(PrivateGroup)
  76. autocodeRouter.InitUnitUserRouter(PrivateGroup)
  77. autocodeRouter.InitUnitPlaceRouter(PrivateGroup)
  78. autocodeRouter.InitAssignmentRouter(PrivateGroup)
  79. // Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
  80. }
  81. InstallPlugin(PublicGroup, PrivateGroup) // 安装插件
  82. global.GVA_LOG.Info("router register success")
  83. return Router
  84. }