GoTomato/cmd/server/main.go
Sebastian Mark 9615d4d449 feat: implement permanent broadcast message functionality
- add SendPermanentBroadCastMessage to continuously send updates
- refactor BroadcastMessage to use a shared Message struct
- update pomodoro logic to modify broadcast.Message directly
- adjust client command handling to use broadcast.Clients map
- enhance ServerMessage struct with "Ongoing" and "Paused" fields

🤖
2024-10-21 13:07:19 +02:00

34 lines
924 B
Go

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"
"net/http"
)
func Start() {
// Define CLI flags for ListenAddress and ListenPort
listenAddress := flag.String("listenAddress", "0.0.0.0", "IP address to listen on")
listenPort := flag.Int("listenPort", 8080, "Port to listen on")
flag.Parse()
serverConfig := models.GoTomatoServerConfig{
ListenAddress: *listenAddress,
ListenPort: *listenPort,
}
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
http.HandleFunc("/ws", websocket.HandleConnections)
go broadcast.SendPermanentBroadCastMessage()
log.Printf("Pomodoro WebSocket server started on %s\n", listen)
err := http.ListenAndServe(listen, nil)
if err != nil {
log.Fatalf("Error starting server: %v", err)
}
}