test: Go/JS SDK 接入清单集成测与 README 示例

This commit is contained in:
Nixevol
2026-09-30 08:35:09 +08:00
parent 77d2dbddb1
commit 2f750bcb0f
12 changed files with 1881 additions and 6 deletions
+30 -2
View File
@@ -15,8 +15,8 @@ func (c *Client) handleDown(payload []byte) {
if err := unmarshalJSON(payload, &head); err != nil {
return
}
switch head.Type {
case "resp":
// resp 必须在收包路径同步处理,否则 request/ack 在 downLoop 里等待时会死锁。
if head.Type == "resp" {
var rf respFrame
if err := unmarshalJSON(payload, &rf); err != nil {
return
@@ -33,6 +33,34 @@ func (c *Client) handleDown(payload []byte) {
default:
}
}
return
}
cp := append([]byte(nil), payload...)
select {
case c.downCh <- cp:
case <-c.ctx.Done():
}
}
func (c *Client) downLoop(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
case payload := <-c.downCh:
c.handleDownApp(payload)
}
}
}
func (c *Client) handleDownApp(payload []byte) {
var head struct {
Type string `json:"type"`
}
if err := unmarshalJSON(payload, &head); err != nil {
return
}
switch head.Type {
case "msg":
c.handleMsg(payload)
case "receipt":