GoTomato/cmd/server/main.go
Sebastian Mark 1a47c0607b feat: update protocol version handling
- add ProtocolVersion variable to metadata package
- don't set `ServerMessage.ProtocolVersion` in `main`
- update `ServerMessage` default to include ProtocolVersion

🤖
2024-10-27 22:46:58 +01:00

46 lines
1.4 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"
"github.com/charmbracelet/log"
"net/http"
"os"
)
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()
if *showVersionFlag {
fmt.Printf("App-Version: %s\n", metadata.GoTomatoVersion)
fmt.Printf("Protocol-Version: %s\n", metadata.ProtocolVersion)
os.Exit(0)
}
serverConfig := models.ServerConfig{
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.Info("GoTomato started", "version", metadata.GoTomatoVersion)
log.Info("Websocket listening", "address", listen)
err := http.ListenAndServe(listen, nil)
if err != nil {
log.Fatal("Error starting server:", "msg", err)
}
}