From ebb58a44893fb09ab57189461f13804c28534eb4 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Wed, 30 Oct 2024 09:57:09 +0100 Subject: [PATCH] feat: rename `Client` model to `WebsocketClient` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 --- internal/websocket/client_commands.go | 2 +- internal/websocket/handle_connection.go | 4 ++-- pkg/models/client.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index 4ea7e7d..59e603a 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -10,7 +10,7 @@ import ( ) // Listens for commands from a client and handles them -func handleClientCommands(c models.Client) { +func handleClientCommands(c models.WebsocketClient) { ws := c.Conn for { var clientCommand models.ClientCommand diff --git a/internal/websocket/handle_connection.go b/internal/websocket/handle_connection.go index 37160d8..dc5ad1c 100644 --- a/internal/websocket/handle_connection.go +++ b/internal/websocket/handle_connection.go @@ -10,7 +10,7 @@ import ( ) // 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 Clients = make(map[*websocket.Conn]*models.WebsocketClient) var mu sync.Mutex // Mutex to protect access to the Clients map // Upgrade HTTP requests to WebSocket connections @@ -31,7 +31,7 @@ func HandleConnection(w http.ResponseWriter, r *http.Request) { log.Info("Client connected", "host", ws.NetConn().RemoteAddr(), "clients", len(Clients)+1) // Register the new client - client := models.Client{ + client := models.WebsocketClient{ Conn: ws, } mu.Lock() diff --git a/pkg/models/client.go b/pkg/models/client.go index f9eb116..c0998f8 100644 --- a/pkg/models/client.go +++ b/pkg/models/client.go @@ -13,13 +13,13 @@ type ClientCommand struct { } // Represents a single client -type Client struct { +type WebsocketClient struct { Conn *websocket.Conn } // Sends a message to the websocket. // Automatically locks and unlocks the client mutex, to ensure that only one goroutine can write at a time. -func (c *Client) SendMessage(messageType int, data []byte) error { +func (c *WebsocketClient) SendMessage(messageType int, data []byte) error { err := c.Conn.WriteMessage(messageType, data) if err != nil { log.Error("Error writing to WebSocket:", "msg", err)