Peer Interface 수정

This commit is contained in:
2023-12-22 11:36:55 +09:00
parent 00f4cab992
commit 0c7698676b
3 changed files with 13 additions and 0 deletions

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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)
}()