refactor: move Clients map and mutex to handle_connections
- move Clients map definition to handle_connections.go
- move mutex definition to handle_connections.go
- remove unused import in client_commands.go
🤖
This commit is contained in:
parent
d0e1162726
commit
d2e34e84f8
2 changed files with 5 additions and 5 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 },
|
||||
|
|
Loading…
Reference in a new issue