From 68b5784255299c8e11e40188351b25aef0cfa2fb Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 21 Nov 2024 09:33:29 +0100 Subject: [PATCH] move websocket vars and const to `vars.go` --- internal/websocket/handle_connection.go | 6 ------ internal/websocket/timeouts.go | 5 ----- internal/websocket/vars.go | 18 ++++++++++++++++++ 3 files changed, 18 insertions(+), 11 deletions(-) delete mode 100644 internal/websocket/timeouts.go create mode 100644 internal/websocket/vars.go diff --git a/internal/websocket/handle_connection.go b/internal/websocket/handle_connection.go index cdb11cd..ca55229 100644 --- a/internal/websocket/handle_connection.go +++ b/internal/websocket/handle_connection.go @@ -2,19 +2,13 @@ package websocket import ( "github.com/gorilla/websocket" - "net" "net/http" - "sync" "time" "git.smsvc.net/pomodoro/GoTomato/internal/helper" "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) -// Clients is a map of connected WebSocket clients, where each client is represented by the WebsocketClient struct -var Clients = make(map[net.Addr]*models.WebsocketClient) -var mu sync.Mutex // Mutex to protect access to the Clients map - // Upgrade HTTP requests to WebSocket connections var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, diff --git a/internal/websocket/timeouts.go b/internal/websocket/timeouts.go deleted file mode 100644 index 4a926f9..0000000 --- a/internal/websocket/timeouts.go +++ /dev/null @@ -1,5 +0,0 @@ -package websocket - -const SEND_TIMEOUT = 10 -const STALE_CLIENT_TIMEOUT = 90 -const STALE_CHECK_INTERVALL = 30 diff --git a/internal/websocket/vars.go b/internal/websocket/vars.go new file mode 100644 index 0000000..5aedb53 --- /dev/null +++ b/internal/websocket/vars.go @@ -0,0 +1,18 @@ +package websocket + +import ( + "net" + "sync" + + "git.smsvc.net/pomodoro/GoTomato/pkg/models" +) + +const SEND_TIMEOUT = 10 +const STALE_CLIENT_TIMEOUT = 90 +const STALE_CHECK_INTERVALL = 30 + +// Clients is a map of connected WebSocket clients, where each client is represented by the WebsocketClient struct +var Clients = make(map[net.Addr]*models.WebsocketClient) + +// Mutex to protect access to the Clients map +var mu sync.Mutex