docs(comments): 注释中文化 · internal/services/channelbridge(纯替换)
- 只翻注释/文档字符串:剥掉注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态) - 术语对齐既有译法(owner→主人、persona→角色、engage→参与度判定、quiet hours→安静时段、backoff→退避) - 复核:go build 绿 + channelbridge 包测试绿;gofmt 干净
This commit is contained in:
1 parent
61cf80d5ee
commit
093f38d986
28 files changed
+1089
-1089
No files matched your search
@@ -7,13 +7,13 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter"
|
||||
)
|
||||
|
||||
// This file holds the adapter registry and the connect lifecycle of the channel
|
||||
// bridge (design/08 §0): adapters are registered through Add, dialed by Start
|
||||
// (each within connectTimeout), torn down by Stop, and skipped by the credential
|
||||
// gate when they carry no usable configuration.
|
||||
// 本文件承载渠道桥接器的适配器注册表与连接生命周期
|
||||
// (design/08 §0):适配器经 Add 注册、由 Start 拨号
|
||||
// (各自受 connectTimeout 约束)、由 Stop 拆除,并在不带
|
||||
// 可用配置时被凭据闸门跳过。
|
||||
|
||||
// Add registers an adapter by its Name. It is safe to call before Start; adding
|
||||
// after Start has no effect on already-running adapters.
|
||||
// Add 按适配器的 Name 注册它。在 Start 之前调用是安全的;
|
||||
// Start 之后再添加不影响已在运行的适配器。
|
||||
func (b *Bridge) Add(a adapter.PlatformAdapter) {
|
||||
if a == nil {
|
||||
return
|
||||
@@ -23,11 +23,11 @@ func (b *Bridge) Add(a adapter.PlatformAdapter) {
|
||||
b.adapters[a.Name()] = a
|
||||
}
|
||||
|
||||
// WebhookHandlers returns the inbound HTTP handlers of every registered adapter
|
||||
// that exposes an HTTP callback (e.g. *webhook.Adapter), keyed by the endpoint
|
||||
// path from the adapter's config. The gateway mounts these to receive external
|
||||
// webhook callbacks into the runtime. A nil map is returned when no adapter
|
||||
// provides an inbound handler.
|
||||
// WebhookHandlers 返回每个暴露 HTTP 回调的已注册适配器
|
||||
// (如 *webhook.Adapter)的入站 HTTP 处理器,键为适配器配置中的
|
||||
// 端点路径。gateway 挂载它们,把外部 webhook 回调
|
||||
// 接入运行时。当没有任何适配器提供入站处理器时
|
||||
// 返回 nil map。
|
||||
func (b *Bridge) WebhookHandlers() map[string]http.Handler {
|
||||
b.mu.RLock()
|
||||
defer b.mu.RUnlock()
|
||||
@@ -39,8 +39,8 @@ func (b *Bridge) WebhookHandlers() map[string]http.Handler {
|
||||
}
|
||||
path := wh.WebhookPath()
|
||||
if path == "" {
|
||||
// Adapter is not currently exposing a webhook (e.g. a websocket-mode
|
||||
// KOOK); skipping avoids mounting a handler at a stale or colliding route.
|
||||
// 适配器当前未暴露 webhook(例如 websocket 模式的
|
||||
// KOOK);跳过它可避免把处理器挂在过期或冲突的路由上。
|
||||
continue
|
||||
}
|
||||
h := wh.InboundHandler()
|
||||
@@ -55,11 +55,11 @@ func (b *Bridge) WebhookHandlers() map[string]http.Handler {
|
||||
return out
|
||||
}
|
||||
|
||||
// Start connects every configured adapter, installs the inbound handler, and
|
||||
// launches the read loops. Adapters without credentials (or whose Connect fails)
|
||||
// are logged and left disconnected; they never fail startup. Start blocks only
|
||||
// long enough to connect (bounded by connectTimeout per adapter) and returns. It
|
||||
// is idempotent: a second call is a no-op.
|
||||
// Start 连接每个已配置的适配器、装配入站处理器并
|
||||
// 启动读取循环。没有凭据(或 Connect 失败)的适配器
|
||||
// 只记日志并保持未连接;它们绝不会导致启动失败。Start 只
|
||||
// 阻塞到连接完成(每个适配器受 connectTimeout 约束)便返回。它
|
||||
// 是幂等的:第二次调用无副作用。
|
||||
func (b *Bridge) Start() {
|
||||
b.mu.Lock()
|
||||
if b.closed || b.started {
|
||||
@@ -77,8 +77,8 @@ func (b *Bridge) Start() {
|
||||
"registered", len(b.snapshot()))
|
||||
}
|
||||
|
||||
// Stop cancels the read loops, disconnects every adapter and waits for in-flight
|
||||
// message processing to finish. It is idempotent.
|
||||
// Stop 取消读取循环、断开所有适配器,并等待
|
||||
// 处理中的消息完成。它是幂等的。
|
||||
func (b *Bridge) Stop(ctx context.Context) {
|
||||
b.mu.Lock()
|
||||
if b.closed {
|
||||
@@ -99,14 +99,14 @@ func (b *Bridge) Stop(ctx context.Context) {
|
||||
b.log.Info("channel bridge stopped")
|
||||
}
|
||||
|
||||
// IsConnected reports whether the named adapter is currently connected.
|
||||
// IsConnected 报告指定名称的适配器当前是否已连接。
|
||||
func (b *Bridge) IsConnected(name string) bool {
|
||||
b.mu.RLock()
|
||||
defer b.mu.RUnlock()
|
||||
return b.connected[name]
|
||||
}
|
||||
|
||||
// ConnectedCount reports how many adapters are currently connected.
|
||||
// ConnectedCount 报告当前已连接的适配器数量。
|
||||
func (b *Bridge) ConnectedCount() int {
|
||||
b.mu.RLock()
|
||||
defer b.mu.RUnlock()
|
||||
@@ -119,7 +119,7 @@ func (b *Bridge) ConnectedCount() int {
|
||||
return n
|
||||
}
|
||||
|
||||
// snapshot returns a copy of the registered adapters for a lock-free iteration.
|
||||
// snapshot 返回已注册适配器的副本,以便无锁遍历。
|
||||
func (b *Bridge) snapshot() []adapter.PlatformAdapter {
|
||||
b.mu.RLock()
|
||||
defer b.mu.RUnlock()
|
||||
@@ -130,11 +130,11 @@ func (b *Bridge) snapshot() []adapter.PlatformAdapter {
|
||||
return out
|
||||
}
|
||||
|
||||
// configured reports whether the adapter carries enough configuration to attempt
|
||||
// a Connect. It inspects the adapter's own Config() snapshot for the credential
|
||||
// each platform needs, so a bare (empty) adapter is skipped rather than dialed.
|
||||
// This is what keeps weixin-ilink from falling into its blocking QR-login flow
|
||||
// when no bot token is present.
|
||||
// configured 报告适配器是否带有足够配置可供尝试
|
||||
// Connect。它检查适配器自身的 Config() 快照来看各平台所需的
|
||||
// 凭据,因此空壳(无配置)适配器会被跳过而不是拨号。
|
||||
// 正是这一点避免了 weixin-ilink 在缺少 bot token 时
|
||||
// 落入会阻塞的扫码登录流程。
|
||||
func (b *Bridge) configured(a adapter.PlatformAdapter) bool {
|
||||
cfg := a.Config()
|
||||
switch basePlatform(a.Name()) {
|
||||
@@ -146,15 +146,15 @@ func (b *Bridge) configured(a adapter.PlatformAdapter) bool {
|
||||
}
|
||||
return cfgStr(cfg, "listenAddr") != ""
|
||||
case "webhook":
|
||||
// Inbound-only: no external credential is required to hold the session.
|
||||
// 仅入站:维持会话不需要外部凭据。
|
||||
return true
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// cfgStr reads a string field from an adapter config map, returning "" when
|
||||
// absent.
|
||||
// cfgStr 从适配器配置 map 中读取字符串字段,缺失时
|
||||
// 返回 ""。
|
||||
func cfgStr(m map[string]any, key string) string {
|
||||
if m == nil {
|
||||
return ""
|
||||
@@ -165,7 +165,7 @@ func cfgStr(m map[string]any, key string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// adapter returns the registered adapter for a platform name, or nil.
|
||||
// adapter 返回平台名对应的已注册适配器,没有则返回 nil。
|
||||
func (b *Bridge) adapter(platform string) adapter.PlatformAdapter {
|
||||
b.mu.RLock()
|
||||
defer b.mu.RUnlock()
|
||||
|
||||
Reference in new issue
Block a user