feat: create model for server config

- introduce GoTomatoServerConfig
- create instance variable with the current config
- update server to use configurable listen address and port

🤖
This commit is contained in:
Sebastian Mark 2024-10-20 14:31:52 +02:00
parent 3d5cb29c54
commit 09b475dd61
2 changed files with 17 additions and 2 deletions

View file

@ -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)
}

6
pkg/models/config.go Normal file
View file

@ -0,0 +1,6 @@
package models
type GoTomatoServerConfig struct {
ListenAddress string `json:"listenAddress"`
ListenPort int `json:"listenPort"`
}