Files
Cyrene_v2/pkg/plugins/sdk/channel.go
T
Aska 5dae2b9741 fix(gateway): 收敛 sdk.Channel 与 adapter.PlatformAdapter 接口漂移,/admin/channels 恢复枚举
根因:sdk.Channel.Connect 为 2 参 (ctx, config any),adapter.PlatformAdapter.Connect 为
1 参 (ctx),Go 无重载 → 4 个渠道(qq-obv11/weixin-ilink/telegram/webhook)只实现 1 参
Connect,类型断言 cap.Value.(sdk.Channel) 恒失败 → /api/v1/admin/channels 恒返回 []。

收敛方向:sdk.Channel.Connect 改 1 参 (ctx),与 PlatformAdapter 生命周期子集一致;
4 个真实适配器自动满足新接口,adminListChannels 枚举成功。最小改动(不改渠道实现、
不引依赖)。同步修正 sdk_test/registry_test/extra_test 的 mock。
2026-09-06 14:04:52 +08:00

30 lines
1.3 KiB
Go

package sdk
import "context"
// Channel registers a chat platform adapter (QQ, WeChat, Telegram, ...).
//
// The SDK pins only the lifecycle shape. The authoritative contract for
// adapters lives in internal/channel/adapter (design authority
// DevDocs/design/08-渠道接入.md §1, the PlatformAdapter contract) and is
// implemented in milestone M6. This interface mirrors the lifecycle portion of
// that contract — Name/Connect/Disconnect/IsConnected/HealthCheck — without
// depending on the internal message model, so a platform plugin can register
// itself here while the message flow is provided by the channel layer.
//
// Implementations must be safe for concurrent use.
type Channel interface {
// Name returns the platform identifier (for example "qq", "telegram").
Name() string
// Connect establishes the platform connection. It may be called more than
// once and must be idempotent.
Connect(ctx context.Context) error
// Disconnect tears the connection down gracefully. It returns nil when the
// adapter was already disconnected.
Disconnect(ctx context.Context) error
// IsConnected reports whether the connection is currently up.
IsConnected() bool
// HealthCheck probes the platform and returns an error when it is unhealthy.
HealthCheck(ctx context.Context) error
}