From 8f17e5fe5add6bea1393f95badf20a1ca83b5526 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Wed, 30 Oct 2024 10:24:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=BC=93=E5=AD=98=E9=80=BB?= =?UTF-8?q?=E8=BE=91,=E6=9C=89=E4=BA=9B=E5=93=8D=E5=BA=94=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9C=80=E8=A6=81=E6=A0=B9=E6=8D=AE=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=BF=9B=E8=A1=8C=E5=8C=BA=E5=88=AB=E5=A4=84?= =?UTF-8?q?=E7=90=86,=E4=BD=86=E6=98=AF=E5=AE=9E=E9=99=85=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E5=A4=84=E7=90=86,=E5=9B=BA=E4=B8=AA=E5=88=AB?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=BC=93=E5=AD=98=E4=B8=8B=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index d87eeb5..297cfb2 100644 --- a/client.go +++ b/client.go @@ -85,6 +85,7 @@ func (this *Client) handlerDealMessage(c *client.Client, msg ios.Acker) { return } + //从缓存中获取数据,响应数据中不同类型有不同的处理方式,但是响应无返回该类型,固根据消息id进行缓存 val, _ := this.m.GetAndDel(conv.String(f.MsgID)) var resp any @@ -130,8 +131,11 @@ func (this *Client) handlerDealMessage(c *client.Client, msg ios.Acker) { } // SendFrame 发送数据,并等待响应 -func (this *Client) SendFrame(f *protocol.Frame) (any, error) { +func (this *Client) SendFrame(f *protocol.Frame, cache ...any) (any, error) { f.MsgID = atomic.AddUint32(&this.msgID, 1) + if len(cache) > 0 { + this.m.Set(conv.String(f.MsgID), cache[0]) + } if _, err := this.Client.Write(f.Bytes()); err != nil { return nil, err } @@ -212,7 +216,7 @@ func (this *Client) GetStockMinuteTrade(exchange protocol.Exchange, code string, if err != nil { return nil, err } - result, err := this.SendFrame(f) + result, err := this.SendFrame(f, code) if err != nil { return nil, err } @@ -244,7 +248,7 @@ func (this *Client) GetStockHistoryMinuteTrade(t time.Time, exchange protocol.Ex if err != nil { return nil, err } - result, err := this.SendFrame(f) + result, err := this.SendFrame(f, code) if err != nil { return nil, err } @@ -275,7 +279,7 @@ func (this *Client) GetStockKline(Type protocol.TypeKline, req *protocol.StockKl if err != nil { return nil, err } - result, err := this.SendFrame(f) + result, err := this.SendFrame(f, Type.Uint16()) if err != nil { return nil, err }