From 9b7dc199351ec2e67f3a87bae9615c15bdbaa631 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 21 Nov 2024 12:25:45 +0100 Subject: [PATCH] feat: introduce `vars.go` for websocket package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - update comments - move `Done` variable to vars.go - move `Connected()` method 🤖 --- internal/websocket/connect.go | 11 ++++++----- internal/websocket/receive.go | 2 -- internal/websocket/vars.go | 4 ++++ 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 internal/websocket/vars.go diff --git a/internal/websocket/connect.go b/internal/websocket/connect.go index 5e063c8..7dd7b57 100644 --- a/internal/websocket/connect.go +++ b/internal/websocket/connect.go @@ -8,7 +8,8 @@ import ( ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models" ) -type Client ChronoTomato.GoTomatoClient // New websocket client +// New websocket client +type Client ChronoTomato.GoTomatoClient // Connects to websocket func Connect(url string) Client { @@ -17,10 +18,6 @@ func Connect(url string) Client { return Client{Conn: conn, Server: url, LastErr: err} } -func (c Client) Connected() bool { - return c.Conn != nil -} - // Disconnects from websocket func (c Client) Disconnect() { // Cleanly close the connection by sending a close message and then @@ -34,3 +31,7 @@ func (c Client) Disconnect() { } return } + +func (c Client) Connected() bool { + return c.Conn != nil +} diff --git a/internal/websocket/receive.go b/internal/websocket/receive.go index 6aca107..bd3e91e 100644 --- a/internal/websocket/receive.go +++ b/internal/websocket/receive.go @@ -9,8 +9,6 @@ import ( GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) -var Done = make(chan struct{}) - // Receives websocket messages and writes them to a channel. // Closes the channel if websocket closes. func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) { diff --git a/internal/websocket/vars.go b/internal/websocket/vars.go new file mode 100644 index 0000000..a9896e2 --- /dev/null +++ b/internal/websocket/vars.go @@ -0,0 +1,4 @@ +package websocket + +// Websocket closure +var Done = make(chan struct{})