router.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package init_serve
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/swaggo/gin-swagger"
  5. "github.com/swaggo/gin-swagger/swaggerFiles"
  6. _ "hongze/fms_api/docs"
  7. "hongze/fms_api/global"
  8. "hongze/fms_api/middleware"
  9. "hongze/fms_api/routers"
  10. )
  11. // InitRouter 初始化路由
  12. func InitRouter() (r *gin.Engine) {
  13. //设置
  14. gin.SetMode(global.CONFIG.Serve.RunMode)
  15. // 1.创建路由
  16. r = gin.Default()
  17. r.Use(middleware.Cors())
  18. //r.Use(gin.Recovery())
  19. r.Use(middleware.Recover())
  20. // 公共的中间件
  21. r.Use(middleware.Common())
  22. //swagger界面访问地址 http://localhost:8390/swagger/index.html
  23. r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  24. rBase := r.Group("api/")
  25. //系统相关路由
  26. systemGroup := rBase.Group("system/")
  27. resourceGroup := rBase.Group("resource/")
  28. routers.InitSystem(systemGroup)
  29. routers.InitAuth(rBase)
  30. routers.InitResource(resourceGroup)
  31. // CRM系统相关路由
  32. crmGroup := rBase.Group("crm/")
  33. routers.InitCrm(crmGroup)
  34. // 合同相关路由
  35. contractGroup := rBase.Group("contract/")
  36. routers.InitContract(contractGroup)
  37. // 统计相关路由
  38. censusGroup := rBase.Group("census/")
  39. routers.InitCensus(censusGroup)
  40. // 统计报告
  41. routers.InitStatistic(rBase)
  42. return
  43. }