router.go 968 B

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