router.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * @desc:路由绑定
  3. * @company:云南奇讯科技有限公司
  4. * @Author: yixiaohu
  5. * @Date: 2022/2/18 16:23
  6. */
  7. package router
  8. import (
  9. "context"
  10. "github.com/gogf/gf/v2/net/ghttp"
  11. commonRouter "github.com/tiger1103/gfast/v3/internal/app/common/router"
  12. commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
  13. systemRouter "github.com/tiger1103/gfast/v3/internal/app/system/router"
  14. "github.com/tiger1103/gfast/v3/library/libRouter"
  15. )
  16. var R = new(Router)
  17. type Router struct{}
  18. func (router *Router) BindController(ctx context.Context, group *ghttp.RouterGroup) {
  19. group.Group("/api/v1", func(group *ghttp.RouterGroup) {
  20. //跨域处理,安全起见正式环境请注释该行
  21. group.Middleware(commonService.Middleware().MiddlewareCORS)
  22. group.Middleware(ghttp.MiddlewareHandlerResponse)
  23. // 绑定后台路由
  24. systemRouter.R.BindController(ctx, group)
  25. // 绑定公共路由
  26. commonRouter.R.BindController(ctx, group)
  27. //自动绑定定义的模块
  28. if err := libRouter.RouterAutoBind(ctx, router, group); err != nil {
  29. panic(err)
  30. }
  31. })
  32. }