websocket.Conn 을 래핑하는 구조체 추가 - 동시 write 오류 제거용

This commit is contained in:
2024-07-24 16:18:40 +09:00
parent 3e46293efc
commit ffa3cc881e
3 changed files with 107 additions and 23 deletions

View File

@ -7,7 +7,6 @@ import (
"strings"
"unsafe"
"github.com/gorilla/websocket"
"repositories.action2quare.com/ayo/gocommon/logger"
)
@ -17,7 +16,7 @@ const (
)
type apiFuncType func(ApiCallContext)
type connFuncType func(*websocket.Conn, *Sender)
type connFuncType func(*Conn, *Sender)
type disconnFuncType func(string, *Sender)
type WebsocketApiHandler struct {
@ -53,7 +52,7 @@ func MakeWebsocketApiHandler[T any](receiver *T, receiverName string) WebsocketA
if method.Type.NumIn() != 3 {
continue
}
if method.Type.In(1) != reflect.TypeOf((*websocket.Conn)(nil)) {
if method.Type.In(1) != reflect.TypeOf((*Conn)(nil)) {
continue
}
if method.Type.In(2) != reflect.TypeOf((*Sender)(nil)) {
@ -62,9 +61,9 @@ func MakeWebsocketApiHandler[T any](receiver *T, receiverName string) WebsocketA
funcptr := method.Func.Pointer()
p1 := unsafe.Pointer(&funcptr)
p2 := unsafe.Pointer(&p1)
connfuncptr := (*func(*T, *websocket.Conn, *Sender))(p2)
connfuncptr := (*func(*T, *Conn, *Sender))(p2)
connfunc = func(c *websocket.Conn, s *Sender) {
connfunc = func(c *Conn, s *Sender) {
(*connfuncptr)(receiver, c, s)
}
} else if method.Name == ClientDisconnected {