router.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package initialize
  2. import (
  3. "mtp20access/api/console"
  4. "mtp20access/global"
  5. "mtp20access/middleware"
  6. "mtp20access/router"
  7. _ "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. Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  21. global.M2A_LOG.Info("register swagger handler")
  22. Router.GET("/debug/console", console.Console)
  23. Router.GET("/debug/update", console.MakeUpdateScript)
  24. }
  25. // 非鉴权组
  26. publicGroup := Router.Group("")
  27. {
  28. router.InitAccountPublicRouter(publicGroup)
  29. }
  30. // 鉴权组
  31. privateGroup := Router.Group("")
  32. privateGroup.Use(middleware.JWTAuth())
  33. {
  34. router.InitMQPrivateRouter(privateGroup)
  35. }
  36. return Router
  37. }