Files
geMoldInsight/src/api/v1/__init__.py
T

29 lines
923 B
Python
Raw Normal View History

2026-04-23 23:37:39 +08:00
from fastapi import APIRouter
2026-04-23 23:57:34 +08:00
import importlib
2026-04-23 23:37:39 +08:00
2026-04-23 23:57:34 +08:00
from utils.logger import get_logger
logger = get_logger(__name__)
2026-04-23 23:37:39 +08:00
router = APIRouter()
2026-04-23 23:57:34 +08:00
def _safe_include(module_path: str, label: str):
try:
module = importlib.import_module(module_path)
router_obj = getattr(module, "router", None)
if router_obj is None:
raise ValueError("未找到 router 对象")
router.include_router(router_obj)
logger.info(f"{label} 路由加载成功")
except Exception as exc:
logger.warning(f"{label} 路由加载失败,已跳过: {exc}")
_safe_include("api.v1.health_router", "健康检查")
_safe_include("api.v1.upload_router", "上传")
_safe_include("api.v1.task_router", "任务")
_safe_include("api.v1.history_router", "历史")
_safe_include("api.v1.debug_router", "调试")
2026-05-02 00:39:04 +08:00
_safe_include("api.v1.cam_router", "CAM")
2026-04-23 23:57:34 +08:00
_safe_include("api.v1.advanced_router", "高级")