From 2aa8163189f1ac7c3162fbbd38058871283e5a6e Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Tue, 22 Oct 2024 17:18:05 +0200 Subject: [PATCH] feat(readme): add protocol version to server messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - define GoTomatoVersion constant for versioning - add version field to all server message examples - add `-version` cli parameter 🤖 --- README.md | 15 ++++++++------- cmd/server/main.go | 11 +++++++++++ internal/metadata/version.go | 3 +++ pkg/models/server.go | 1 + 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 internal/metadata/version.go diff --git a/README.md b/README.md index c97da81..d382d61 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,15 @@ The server periodically (every second) sends JSON-encoded messages to all connec - time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes). - ongoing: Whether a Pomodoro session is currently ongoing. - paused: Whether the timer is paused. +* version: The protocol version of the send message (this is always the same as the major app version) -| Message Type | Example | -| --- | --- | -| Welcome Message | {"mode":"Idle", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":1500, "ongoing":false, "paused":false} | -| Session Running | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":1, "time_left":900, "ongoing":true, "paused":false} | -| Session Running | {"mode":"ShortBreak", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":50, "ongoing":true, "paused":false} | -| Session Paused | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":456, "ongoing":true, "paused":true} | -| Session End/Reset | {"mode":"End", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":0, "ongoing":false, "paused":false} | +| Message Type | Example | +| --- | --- | +| Welcome Message | {"mode":"Idle", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":1500, "ongoing":false, "paused":false, "version":"v0"} | +| Session Running | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":1, "time_left":900, "ongoing":true, "paused":false, "version":"v0"} | +| Session Running | {"mode":"ShortBreak", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":50, "ongoing":true, "paused":false, "version":"v0"} | +| Session Paused | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":456, "ongoing":true, "paused":true, "version":"v0"} | +| Session End/Reset | {"mode":"End", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":0, "ongoing":false, "paused":false, "version":"v0"} | ## Testing diff --git a/cmd/server/main.go b/cmd/server/main.go index 101c14d..828602b 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,11 +3,14 @@ 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() { @@ -15,8 +18,16 @@ func Start() { 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, diff --git a/internal/metadata/version.go b/internal/metadata/version.go new file mode 100644 index 0000000..89b5b3c --- /dev/null +++ b/internal/metadata/version.go @@ -0,0 +1,3 @@ +package metadata + +const GoTomatoVersion = "v0.0.1" // The GoTomato Version diff --git a/pkg/models/server.go b/pkg/models/server.go index 29780f0..c95d5f2 100644 --- a/pkg/models/server.go +++ b/pkg/models/server.go @@ -8,4 +8,5 @@ type ServerMessage struct { TimeLeft int `json:"time_left"` // Remaining time in seconds Ongoing bool `json:"ongoing"` // Ongoing pomodoro Paused bool `json:"paused"` // Is timer paused + GoTomatoVersion string `json:"version"` // Version of the server }