From 0c7698676b05dae1095958e84ce1b86d21392a14 Mon Sep 17 00:00:00 2001 From: mountain Date: Fri, 22 Dec 2023 11:36:55 +0900 Subject: [PATCH] =?UTF-8?q?Peer=20Interface=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wshandler/api_handler_peer.go | 2 ++ wshandler/api_handler_test.go | 9 +++++++++ wshandler/wshandler_peer.go | 2 ++ 3 files changed, 13 insertions(+) diff --git a/wshandler/api_handler_peer.go b/wshandler/api_handler_peer.go index 0d782ec..7c43b18 100644 --- a/wshandler/api_handler_peer.go +++ b/wshandler/api_handler_peer.go @@ -7,12 +7,14 @@ import ( "reflect" "strings" + "github.com/gorilla/websocket" "go.mongodb.org/mongo-driver/bson/primitive" "repositories.action2quare.com/ayo/gocommon/logger" ) type PeerInterface interface { ClientDisconnected(string) + ClientConnected(*websocket.Conn) } type peerApiFuncType[T PeerInterface] func(T, io.Reader) (any, error) diff --git a/wshandler/api_handler_test.go b/wshandler/api_handler_test.go index 3c35820..9d06319 100644 --- a/wshandler/api_handler_test.go +++ b/wshandler/api_handler_test.go @@ -108,3 +108,12 @@ func TestPeerApiBroker(t *testing.T) { func1args, _ = json.Marshal([]any{float64(111.1), []int{99, 98}}) ws.Call(tp, "test.ApiFunc3", bytes.NewBuffer(func1args)) } + +func TestUnmarshal(t *testing.T) { + src := []byte(`{"123" :"str1", "456": "str2"}`) + var test map[int]string + err := json.Unmarshal(src, &test) + if err != nil { + t.Error(err) + } +} diff --git a/wshandler/wshandler_peer.go b/wshandler/wshandler_peer.go index 3af127b..49a6f09 100644 --- a/wshandler/wshandler_peer.go +++ b/wshandler/wshandler_peer.go @@ -45,6 +45,8 @@ func (ws *WebsocketPeerHandler[T]) upgrade_core(conn *websocket.Conn, accid prim peer := ws.CreatePeer(accid) var closeReason string + peer.ClientConnected(conn) + defer func() { peer.ClientDisconnected(closeReason) }()