router.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from fastapi import APIRouter
  2. from app.api.endpoints import (
  3. account,
  4. auth,
  5. common,
  6. config,
  7. email,
  8. notification,
  9. order,
  10. payment,
  11. product,
  12. proxy,
  13. slot,
  14. sms,
  15. task,
  16. ticket,
  17. user,
  18. vas_task,
  19. webhook,
  20. )
  21. # 公共路由
  22. public_router = APIRouter()
  23. # 受保护路由
  24. protected_router = APIRouter()
  25. # 管理员级别路由
  26. admin_required_router = APIRouter()
  27. # 模块列表
  28. _modules = [
  29. account,
  30. auth,
  31. common,
  32. config,
  33. email,
  34. notification,
  35. order,
  36. payment,
  37. product,
  38. proxy,
  39. slot,
  40. sms,
  41. task,
  42. ticket,
  43. user,
  44. vas_task,
  45. webhook,
  46. ]
  47. # 注册所有子模块路由
  48. for _mod in _modules:
  49. if hasattr(_mod, "public_router") and _mod.public_router.routes:
  50. public_router.include_router(_mod.public_router)
  51. if hasattr(_mod, "protected_router") and _mod.protected_router.routes:
  52. protected_router.include_router(_mod.protected_router)
  53. if hasattr(_mod, "admin_required_router") and _mod.admin_required_router.routes:
  54. admin_required_router.include_router(_mod.admin_required_router)