HOST Variable

This commit is contained in:
2026-03-06 17:16:56 +02:00
parent ec8e8911ce
commit 3ffe0d4958
4 changed files with 18 additions and 1 deletions

View File

@@ -3,11 +3,17 @@ package config
import "os"
type Config struct {
Host string
Port string
DataPath string
}
func Load() Config {
host := os.Getenv("HOST")
if host == "" {
host = "0.0.0.0"
}
port := os.Getenv("PORT")
if port == "" {
port = "8002"
@@ -19,6 +25,7 @@ func Load() Config {
}
return Config{
Host: host,
Port: port,
DataPath: dataPath,
}

View File

@@ -2,6 +2,7 @@ package main
import (
"log"
"net"
"scrum-solitare/src/config"
"scrum-solitare/src/handlers"
@@ -21,7 +22,7 @@ func main() {
rooms := handlers.NewRoomAPIHandler(manager)
router := server.NewRouter(pages, rooms)
if err := router.Run(":" + cfg.Port); err != nil {
if err := router.Run(net.JoinHostPort(cfg.Host, cfg.Port)); err != nil {
log.Fatalf("server failed to start: %v", err)
}
}