From 09b475dd61782bbca1a9ba1290c632fd3baf90b4 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sun, 20 Oct 2024 14:31:52 +0200 Subject: [PATCH] feat: create model for server config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - introduce GoTomatoServerConfig - create instance variable with the current config - update server to use configurable listen address and port 🤖 --- cmd/server/main.go | 13 +++++++++++-- pkg/models/config.go | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 pkg/models/config.go diff --git a/cmd/server/main.go b/cmd/server/main.go index 6470e4d..3d1c9f8 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -1,16 +1,25 @@ package server import ( + "fmt" "git.smsvc.net/pomodoro/GoTomato/internal/websocket" + "git.smsvc.net/pomodoro/GoTomato/pkg/models" "log" "net/http" ) +var serverConfig = models.GoTomatoServerConfig{ + ListenAddress: "0.0.0.0", + ListenPort: 8080, +} + func Start() { + listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort) + http.HandleFunc("/ws", websocket.HandleConnections) - log.Println("Pomodoro WebSocket server started on :8080") - err := http.ListenAndServe(":8080", nil) + 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) } diff --git a/pkg/models/config.go b/pkg/models/config.go new file mode 100644 index 0000000..59db277 --- /dev/null +++ b/pkg/models/config.go @@ -0,0 +1,6 @@ +package models + +type GoTomatoServerConfig struct { + ListenAddress string `json:"listenAddress"` + ListenPort int `json:"listenPort"` +}