refactor: move broadcast package to websocket

- 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

🤖
This commit is contained in:
Sebastian Mark 2024-10-21 09:24:20 +02:00
parent aab6896c7d
commit 6ffd9f1e38
2 changed files with 3 additions and 5 deletions

View file

@ -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)

View file

@ -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)