From f5e4ac14158d4a96801a2a0ae284ae4a65fede8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20L=C3=B6ffel?= Date: Fri, 6 Jul 2018 00:17:05 +0200 Subject: [PATCH 1/3] fixed typo --- recws.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/recws.go b/recws.go index 077eff4..2b0c28a 100644 --- a/recws.go +++ b/recws.go @@ -47,8 +47,8 @@ type RecConn struct { *websocket.Conn } -// CloseAndRecconect will try to reconnect. -func (rc *RecConn) closeAndRecconect() { +// CloseAndReconnect will try to reconnect. +func (rc *RecConn) closeAndReconnect() { rc.Close() go func() { rc.connect() @@ -76,7 +76,7 @@ func (rc *RecConn) ReadMessage() (messageType int, message []byte, err error) { if rc.IsConnected() { messageType, message, err = rc.Conn.ReadMessage() if err != nil { - rc.closeAndRecconect() + rc.closeAndReconnect() } } @@ -92,7 +92,7 @@ func (rc *RecConn) WriteMessage(messageType int, data []byte) error { if rc.IsConnected() { err = rc.Conn.WriteMessage(messageType, data) if err != nil { - rc.closeAndRecconect() + rc.closeAndReconnect() } } @@ -110,7 +110,7 @@ func (rc *RecConn) WriteJSON(v interface{}) error { if rc.IsConnected() { err = rc.Conn.WriteJSON(v) if err != nil { - rc.closeAndRecconect() + rc.closeAndReconnect() } } From 6fe8fd6ea5e039612f3fb5d025a97d726de3d354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20L=C3=B6ffel?= Date: Fri, 6 Jul 2018 00:20:22 +0200 Subject: [PATCH 2/3] added goland ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8f5fd87..c610222 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .history +/.idea \ No newline at end of file From b501600fcce2f5b04884c55fe9fd6b72ae5ce22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20L=C3=B6ffel?= Date: Fri, 6 Jul 2018 01:09:36 +0200 Subject: [PATCH 3/3] Added ReadJSON --- recws.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/recws.go b/recws.go index 2b0c28a..63c91aa 100644 --- a/recws.go +++ b/recws.go @@ -117,6 +117,25 @@ func (rc *RecConn) WriteJSON(v interface{}) error { return err } +// ReadJSON reads the next JSON-encoded message from the connection and stores +// it in the value pointed to by v. +// +// See the documentation for the encoding/json Unmarshal function for details +// about the conversion of JSON to a Go value. +// +// If the connection is closed ErrNotConnected is returned +func (rc *RecConn) ReadJSON(v interface{}) error { + err := ErrNotConnected + if rc.IsConnected() { + err = rc.Conn.ReadJSON(v) + if err != nil { + rc.closeAndReconnect() + } + } + + return err +} + // Dial creates a new client connection. // The URL url specifies the host and request URI. Use requestHeader to specify // the origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies