Sebastian Mark
232fe409cb
- define GoTomatoVersion constant for versioning
- add protocol version field to all server messages
- add `-version` cli parameter
- update README
🤖
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"git.smsvc.net/pomodoro/GoTomato/internal/metadata"
|
|
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
|
"git.smsvc.net/pomodoro/GoTomato/internal/websocket"
|
|
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func Start() {
|
|
// Define CLI flags for ListenAddress and ListenPort
|
|
listenAddress := flag.String("listenAddress", shared.DefaultServerConfig.ListenAddress, "IP address to listen on")
|
|
listenPort := flag.Int("listenPort", shared.DefaultServerConfig.ListenPort, "Port to listen on")
|
|
password := flag.String("password", "", "Control password for pomodoro session (optional)")
|
|
showVersionFlag := flag.Bool("version", false, "Output version")
|
|
flag.Parse()
|
|
|
|
shared.Message.GoTomatoVersion = strings.Split(metadata.GoTomatoVersion, ".")[0]
|
|
if *showVersionFlag {
|
|
fmt.Printf("App-Version: %s\n", metadata.GoTomatoVersion)
|
|
fmt.Printf("Protocol-Version: %s\n", shared.Message.GoTomatoVersion)
|
|
os.Exit(0)
|
|
}
|
|
|
|
serverConfig := models.GoTomatoServerConfig{
|
|
ListenAddress: *listenAddress,
|
|
ListenPort: *listenPort,
|
|
}
|
|
shared.PomodoroPassword = *password
|
|
|
|
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
|
|
|
|
http.HandleFunc("/ws", websocket.HandleConnections)
|
|
go websocket.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)
|
|
}
|
|
}
|