【架构优化】合并 botinteraction/socket.go dial 中三处重复的帧 JSON 键收集排序逻辑
维护者通常 1 天内回复
评估
调研方向
The work is in internal/botinteraction/socket.go, inside the read-loop goroutine of dial, where three near-identical blocks unmarshal the body, event and template_card_event levels, collect keys and sort them. Read that block and the existing frame logging first. Extract the shared logic into a private helper, then add a unit test file for nested keys, missing levels, invalid JSON and empty input. Note that pull request #428 is already open against this issue, so check it before starting. Done means go vet and go test ./internal/botinteraction/... pass with the log format unchanged.
由索引模型根据 Issue 内容生成。
描述
现状问题
internal/botinteraction/socket.go 的 dial 函数约 75 行,读循环 goroutine 中内联了一段约 25 行的帧诊断日志逻辑:对 body、body.event、body.event.template_card_event 三层 JSON 分别执行「Unmarshal → 收集键 → 排序」,三段代码几乎完全重复,使读循环的主流程(ack 分发 / 回调分发)被淹没,也无法单独测试。
重构方案
- 新增包内私有辅助函数
sortedJSONKeys(raw json.RawMessage) ([]string, map[string]json.RawMessage),统一完成解析、取键、排序(解析失败或为空时返回空切片[],与原行为一致)。 - 新增
logFrameKeys(f Frame)封装诊断日志,dial读循环中仅保留一行调用。 - 日志格式
wecom frame cmd=%s body_keys=%v event_keys=%v card_keys=%v及触发条件(Cmd非空且非aibot_msg_callback)保持不变。
影响范围
仅 internal/botinteraction/socket.go 及新增单测文件;无对外接口、协议或行为变化。
验证方式
- 新增单测覆盖:三层嵌套键、缺失层级、非法 JSON、空输入。
go vet ./internal/botinteraction/...、go test ./internal/botinteraction/...通过。
- 主要语言
- Go
- 星标
- 141
- 派生
- 28
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 113
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Tencent/LoopForge 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
[Bug]: 官方镜像未安装 wecom-cli,企业微信通知报「通知服务未安装 wecom-cli」可能已有人在做 @newexploreor 于 1 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
Tencent/LoopForge#156 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
【架构优化】合并 gitwork/workbranch.go 中 push/pull 重复的默认提交身份注入为 withFallbackIdentity可能已有人在做 @fx-kurumi 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 40/100
维护者通常 1 天内回复
-
【架构优化】从 runtime.installNPMCLI 中拆出 npm 参数拼装 npmCLIInstallArgs 与安装结果启用 activateNPMStage可能已有人在做 @fx-kurumi 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 30/100
维护者通常 1 天内回复
查看 Tencent/LoopForge 的全部 Issue
相似的 Issue
-
team:library-maintainers
难度 2/5 1-3 小时 新手友好度 82/100
padok-team/burrito#1208 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
bazel-contrib/rules_go#4784 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 62/100
POSIdev-community/aictl#40 ·
-
难度 1/5 1 小时以内 新手友好度 62/100
prime-radiant-inc/evener#6306 ·
维护者通常 1 天内回复