From 2c3ccc86c3c434d6f1eff49cc7c829061f782ff5 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 21 Nov 2024 09:34:19 +0100 Subject: [PATCH] reorder `staleClients.go` --- internal/websocket/staleClients.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/websocket/staleClients.go b/internal/websocket/staleClients.go index 9d9d713..a3afe14 100644 --- a/internal/websocket/staleClients.go +++ b/internal/websocket/staleClients.go @@ -8,21 +8,6 @@ import ( "github.com/gorilla/websocket" ) -func sendPing(client *models.WebsocketClient) bool { - client.Conn.SetWriteDeadline(time.Now().Add(SEND_TIMEOUT * time.Second)) - err := client.Conn.WriteMessage(websocket.PingMessage, nil) - - if err != nil { - return false - } - - return true -} - -func isStale(client *models.WebsocketClient) bool { - return time.Since(client.LastPong) > (STALE_CLIENT_TIMEOUT * time.Second) -} - // Check and remove stale clients func RemoveStaleClients() { ticker := time.NewTicker(STALE_CHECK_INTERVALL * time.Second) @@ -40,3 +25,18 @@ func RemoveStaleClients() { mu.Unlock() } } + +func sendPing(client *models.WebsocketClient) bool { + client.Conn.SetWriteDeadline(time.Now().Add(SEND_TIMEOUT * time.Second)) + err := client.Conn.WriteMessage(websocket.PingMessage, nil) + + if err != nil { + return false + } + + return true +} + +func isStale(client *models.WebsocketClient) bool { + return time.Since(client.LastPong) > (STALE_CLIENT_TIMEOUT * time.Second) +}