后端模块拆分
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from fastapi import APIRouter
|
||||
import importlib
|
||||
|
||||
from shared.utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
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("moldinsight.api.health_router", "健康检查")
|
||||
_safe_include("moldinsight.api.upload_router", "上传")
|
||||
_safe_include("moldinsight.api.task_router", "任务")
|
||||
_safe_include("moldinsight.api.history_router", "历史")
|
||||
_safe_include("moldinsight.api.debug_router", "调试")
|
||||
_safe_include("moldinsight.api.cam_router", "CAM")
|
||||
_safe_include("moldinsight.api.advanced_router", "高级")
|
||||
Reference in New Issue
Block a user