router.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package initialize
  2. import (
  3. "mtp20access/api/console"
  4. "mtp20access/global"
  5. "mtp20access/middleware"
  6. "mtp20access/router"
  7. docs "mtp20access/docs"
  8. "github.com/gin-gonic/gin"
  9. ginSwagger "github.com/swaggo/gin-swagger"
  10. "github.com/swaggo/gin-swagger/swaggerFiles"
  11. )
  12. func Routers() *gin.Engine {
  13. Router := gin.Default()
  14. // 跨域,如需跨域可以打开下面的注释
  15. Router.Use(middleware.Cors()) // 直接放行全部跨域请求
  16. // Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
  17. //global.GVA_LOG.Info("use middleware cors")
  18. // 开发测试模式
  19. if global.M2A_CONFIG.System.Env == "develop" {
  20. docs.SwaggerInfo.BasePath = "/api"
  21. Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  22. global.M2A_LOG.Info("register swagger handler")
  23. Router.GET("/debug/console", console.Console)
  24. Router.GET("/debug/update", console.MakeUpdateScript)
  25. }
  26. // 非鉴权组
  27. publicGroup := Router.Group("api")
  28. {
  29. // 开发测试模式
  30. if global.M2A_CONFIG.System.Env == "develop" {
  31. router.InitMQPublicRouter(publicGroup)
  32. }
  33. router.InitAccountPublicRouter(publicGroup)
  34. router.InitQuotePublicRouter(publicGroup)
  35. router.InitTradePublicRouter(publicGroup)
  36. }
  37. // 鉴权组
  38. privateGroup := Router.Group("api")
  39. privateGroup.Use(middleware.JWTAuth())
  40. {
  41. router.InitMQPrivateRouter(privateGroup)
  42. router.InitAccountPrivateRouter(privateGroup)
  43. router.InitQuotePrivateRouter(privateGroup)
  44. }
  45. return Router
  46. }