diff --git a/khatru/websocket.go b/khatru/websocket.go index c5b984e..40484c6 100644 --- a/khatru/websocket.go +++ b/khatru/websocket.go @@ -2,6 +2,7 @@ package khatru import ( "context" + "fmt" "net/http" "sync" @@ -31,6 +32,9 @@ type WebSocket struct { } func (ws *WebSocket) WriteJSON(any any) error { + if ws == nil { + return fmt.Errorf("connection doesn't exist") + } ws.mutex.Lock() err := ws.conn.WriteJSON(any) ws.mutex.Unlock()