From 7c9cacc8697b0d1ed5e03cec50ad39398fcca990 Mon Sep 17 00:00:00 2001 From: EasonChen <492926400@qq.com> Date: Wed, 29 May 2024 10:50:15 +0800 Subject: [PATCH] feat: add source field to ConnectMeta (#31) * feat: add source field to ConnectMeta * feat: add source field to IConnectMeta --------- Co-authored-by: chenyuxin2 --- ws/conn.go | 7 ++++++- ws/def.go | 1 + ws/wss_test.go | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ws/conn.go b/ws/conn.go index 67abd98..86c1175 100644 --- a/ws/conn.go +++ b/ws/conn.go @@ -104,6 +104,7 @@ type ConnectionMeta struct { UserId string //userId Typed int //客户端类型枚举 DeviceId string //设备ID + Source string //defines where the connection comes from Version int //版本 Charset int //客户端使用的字符集 @@ -112,7 +113,7 @@ type ConnectionMeta struct { } func (m *ConnectionMeta) BuildConnId() string { - return fmt.Sprintf("%v-%v-%v", m.UserId, m.Typed, m.DeviceId) + return fmt.Sprintf("%v-%v-%v-%v", m.UserId, m.Typed, m.DeviceId, m.Source) } func (c *Connection) Id() string { @@ -131,6 +132,10 @@ func (c *Connection) DeviceId() string { return c.meta.DeviceId } +func (c *Connection) Source() string { + return c.meta.Source +} + func (c *Connection) Version() int { return c.meta.Version } diff --git a/ws/def.go b/ws/def.go index 80387ce..343d72e 100644 --- a/ws/def.go +++ b/ws/def.go @@ -49,6 +49,7 @@ type IConnection interface { UserId() string Type() int DeviceId() string + Source() string Version() int Charset() int ClientIp() string diff --git a/ws/wss_test.go b/ws/wss_test.go index a328ab3..f1f314c 100644 --- a/ws/wss_test.go +++ b/ws/wss_test.go @@ -151,6 +151,7 @@ func TestWssRequestResponse(t *testing.T) { UserId: r.URL.Query().Get("uid"), Typed: 0, DeviceId: "", + Source: "", Version: 0, Charset: 0, } @@ -270,6 +271,7 @@ func TestWssRequestResponseWithTimeout(t *testing.T) { UserId: r.URL.Query().Get("uid"), Typed: 0, DeviceId: "", + Source: "", Version: 0, Charset: 0, } @@ -399,6 +401,7 @@ func TestWssSendMessage(t *testing.T) { UserId: r.URL.Query().Get("uid"), Typed: gocast.ToInt(r.URL.Query().Get("typed")), DeviceId: r.URL.Query().Get("deviceId"), + Source: r.URL.Query().Get("source"), Version: gocast.ToInt(r.URL.Query().Get("version")), Charset: gocast.ToInt(r.URL.Query().Get("charset")), } @@ -535,6 +538,7 @@ func TestWssDialConnect(t *testing.T) { UserId: r.URL.Query().Get("uid"), Typed: 0, DeviceId: "", + Source: "", Version: 0, Charset: 0, } @@ -655,6 +659,7 @@ func TestWssDialRetryConnect(t *testing.T) { UserId: r.URL.Query().Get("uid"), Typed: 0, DeviceId: "", + Source: "", Version: 0, Charset: 0, } @@ -699,6 +704,7 @@ func TestAutoReDialConnect(t *testing.T) { UserId: r.URL.Query().Get("uid"), Typed: 0, DeviceId: "", + Source: "", Version: 0, Charset: 0, }