From a087372bbe75776f1517d1ba1745bec02928b3f7 Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 1 Sep 2023 15:29:26 +0200 Subject: [PATCH] Introduce debug flag. --- main.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 2732a7f..0053a77 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "flag" "fmt" "log" "mchess_server/api" @@ -11,7 +12,6 @@ import ( "mchess_server/usher" "mchess_server/utils" "net/http" - "os" "sync" "github.com/gin-gonic/gin" @@ -25,19 +25,22 @@ var key_file = cert_path + "privkey.pem" var mut sync.Mutex func main() { - hostname, err := os.Hostname() - if err != nil { - log.Fatal(err) + var debugMode bool + + debugModeLong := flag.Bool("debug", false, "activates debug mode") + debugModeShort := flag.Bool("d", false, "activates debug mode") + flag.Parse() + if *debugModeShort || *debugModeLong { + debugMode = true } router := gin.Default() - router.GET("/api/random", registerForRandomGame) router.GET("/api/hostPrivate", hostPrivateGame) router.POST("/api/joinPrivate", joinPrivateGame) router.GET("/api/ws", registerWebSocketConnection) - if hostname == "mbook" { + if debugMode { log.Println("Starting service WITHOUT TLS") log.Fatal(router.Run("localhost:8080")) } else {