package server import ( "github.com/gorilla/websocket" "sync" ) type wsConn struct { conn *websocket.Conn lock *sync.Mutex } func newWsConn(conn *websocket.Conn) *wsConn { return &wsConn{ conn: conn, lock: &sync.Mutex{}, } } func (c *wsConn) Write(msg []byte) error { c.lock.Lock() defer c.lock.Unlock() return c.conn.WriteMessage(websocket.BinaryMessage, msg) }