mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-17 21:32:55 +01:00
25 lines
408 B
Go
25 lines
408 B
Go
|
package relayer
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
|
||
|
"github.com/gorilla/websocket"
|
||
|
)
|
||
|
|
||
|
type WebSocket struct {
|
||
|
conn *websocket.Conn
|
||
|
mutex sync.Mutex
|
||
|
}
|
||
|
|
||
|
func (ws *WebSocket) WriteJSON(any interface{}) error {
|
||
|
ws.mutex.Lock()
|
||
|
defer ws.mutex.Unlock()
|
||
|
return ws.conn.WriteJSON(any)
|
||
|
}
|
||
|
|
||
|
func (ws *WebSocket) WriteMessage(t int, b []byte) error {
|
||
|
ws.mutex.Lock()
|
||
|
defer ws.mutex.Unlock()
|
||
|
return ws.conn.WriteMessage(t, b)
|
||
|
}
|