ForcePilot/backend/package/yuxi/channel/interfaces/rest/router/registry.py
Kris 39b7df2ce0 refactor(channel-domain): 重构端口定义与导入结构
1. 新增多个领域端口协议类,包括签名验证、路由贡献、关键词匹配等完整的端口定义
2. 重构ChannelRouteContributor重命名为ChannelRouteContributorPort并统一导入路径
3. 调整端口目录结构,拆分external和internal子目录并分别导出
4. 更新所有引用了旧端口定义的业务代码和测试用例
2026-05-31 17:38:33 +08:00

42 lines
1.2 KiB
Python

from __future__ import annotations
import logging
from fastapi import FastAPI
from yuxi.channel.domain.port.channel_adapter_port import ChannelAdapterPort
from yuxi.channel.domain.port.channel_route_contributor_port import ChannelRouteContributorPort
logger = logging.getLogger(__name__)
def register_all_channel_routes(
app: FastAPI,
adapters: dict[str, ChannelAdapterPort],
) -> list[str]:
registered: list[str] = []
for name, adapter in adapters.items():
contributor = _get_route_contributor(adapter)
if contributor is None:
continue
router = contributor.router
prefix = f"/channel/{name}"
app.include_router(router, prefix=prefix)
registered.append(prefix)
logger.info("registered channel routes: %s", prefix)
return registered
def _get_route_contributor(adapter: ChannelAdapterPort) -> ChannelRouteContributorPort | None:
contributor = getattr(adapter, "route_contributor", None)
if contributor is None:
return None
if isinstance(contributor, ChannelRouteContributorPort):
return contributor
if hasattr(contributor, "router"):
return contributor
return None