From 6ffd9f1e382852ba5a9b42c686088510c5bacf8c Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Mon, 21 Oct 2024 09:24:20 +0200 Subject: [PATCH] refactor: move broadcast package to websocket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - update import paths to reflect the new package name - change function call to use the new websocket package - adjust client iteration to use the renamed Clients variable 🤖 --- cmd/server/main.go | 3 +-- internal/{broadcast => websocket}/broadcast.go | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) rename internal/{broadcast => websocket}/broadcast.go (86%) diff --git a/cmd/server/main.go b/cmd/server/main.go index bf3f949..b1d9db8 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,7 +3,6 @@ package server import ( "flag" "fmt" - "git.smsvc.net/pomodoro/GoTomato/internal/broadcast" "git.smsvc.net/pomodoro/GoTomato/internal/websocket" "git.smsvc.net/pomodoro/GoTomato/pkg/models" "log" @@ -24,7 +23,7 @@ func Start() { listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort) http.HandleFunc("/ws", websocket.HandleConnections) - go broadcast.SendPermanentBroadCastMessage() + go websocket.SendPermanentBroadCastMessage() log.Printf("Pomodoro WebSocket server started on %s\n", listen) err := http.ListenAndServe(listen, nil) diff --git a/internal/broadcast/broadcast.go b/internal/websocket/broadcast.go similarity index 86% rename from internal/broadcast/broadcast.go rename to internal/websocket/broadcast.go index ac23e7e..728726a 100644 --- a/internal/broadcast/broadcast.go +++ b/internal/websocket/broadcast.go @@ -1,9 +1,8 @@ -package broadcast +package websocket import ( "encoding/json" "git.smsvc.net/pomodoro/GoTomato/internal/shared" - ws "git.smsvc.net/pomodoro/GoTomato/internal/websocket" "github.com/gorilla/websocket" "log" "time" @@ -19,7 +18,7 @@ func SendPermanentBroadCastMessage() { return } // Iterate over all connected clients and broadcast the message - for _, client := range ws.Clients { + for _, client := range Clients { err := client.SendMessage(websocket.TextMessage, jsonMessage) if err != nil { log.Printf("Error broadcasting to client: %v", err)