From d0e1162726aa7ad20d24f58606f5648cef0a80d5 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sun, 20 Oct 2024 20:49:36 +0200 Subject: [PATCH 1/2] feat: add comments for configuration fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add documentation comments for - GoTomatoTimerConfig - GoTomatoServerConfig 🤖 --- pkg/models/config.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/models/config.go b/pkg/models/config.go index 628e685..6bb63a1 100644 --- a/pkg/models/config.go +++ b/pkg/models/config.go @@ -1,13 +1,13 @@ package models type GoTomatoTimerConfig struct { - Work int `json:"work"` - ShortBreak int `json:"shortBreak"` - LongBreak int `json:"longBreak"` - Sessions int `json:"sessions"` + Work int `json:"work"` // Length of work sessions in seconds + ShortBreak int `json:"shortBreak"` // Length of short break in seconds + LongBreak int `json:"longBreak"` // Length if ling break in seconds + Sessions int `json:"sessions"` // Number of total sessions } type GoTomatoServerConfig struct { - ListenAddress string `json:"listenAddress"` - ListenPort int `json:"listenPort"` + ListenAddress string `json:"listenAddress"` // Server listen address + ListenPort int `json:"listenPort"` // Server listen port } From d2e34e84f87f2dfd7e88836a4e30795a6bb3a88e Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sun, 20 Oct 2024 20:51:21 +0200 Subject: [PATCH 2/2] refactor: move Clients map and mutex to handle_connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - move Clients map definition to handle_connections.go - move mutex definition to handle_connections.go - remove unused import in client_commands.go 🤖 --- internal/websocket/client_commands.go | 5 ----- internal/websocket/handle_connections.go | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index c5e5340..b88ca78 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -6,13 +6,8 @@ import ( "git.smsvc.net/pomodoro/GoTomato/pkg/models" "github.com/gorilla/websocket" "log" - "sync" ) -// Clients is a map of connected WebSocket clients, where each client is represented by the Client struct -var Clients = make(map[*websocket.Conn]*models.Client) -var mu sync.Mutex // Mutex to protect access to the Clients map - // handleClientCommands listens for commands from WebSocket clients and dispatches to the timer. func handleClientCommands(ws *websocket.Conn) { for { diff --git a/internal/websocket/handle_connections.go b/internal/websocket/handle_connections.go index 433ff82..be49918 100644 --- a/internal/websocket/handle_connections.go +++ b/internal/websocket/handle_connections.go @@ -5,8 +5,13 @@ import ( "github.com/gorilla/websocket" "log" "net/http" + "sync" ) +// Clients is a map of connected WebSocket clients, where each client is represented by the Client struct +var Clients = make(map[*websocket.Conn]*models.Client) +var mu sync.Mutex // Mutex to protect access to the Clients map + // Upgrader to upgrade HTTP requests to WebSocket connections var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true },