Introduce debug flag.

This commit is contained in:
Marco 2023-09-01 15:29:26 +02:00
parent 72faedc000
commit a087372bbe

15
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"log" "log"
"mchess_server/api" "mchess_server/api"
@ -11,7 +12,6 @@ import (
"mchess_server/usher" "mchess_server/usher"
"mchess_server/utils" "mchess_server/utils"
"net/http" "net/http"
"os"
"sync" "sync"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -25,19 +25,22 @@ var key_file = cert_path + "privkey.pem"
var mut sync.Mutex var mut sync.Mutex
func main() { func main() {
hostname, err := os.Hostname() var debugMode bool
if err != nil {
log.Fatal(err) 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 := gin.Default()
router.GET("/api/random", registerForRandomGame) router.GET("/api/random", registerForRandomGame)
router.GET("/api/hostPrivate", hostPrivateGame) router.GET("/api/hostPrivate", hostPrivateGame)
router.POST("/api/joinPrivate", joinPrivateGame) router.POST("/api/joinPrivate", joinPrivateGame)
router.GET("/api/ws", registerWebSocketConnection) router.GET("/api/ws", registerWebSocketConnection)
if hostname == "mbook" { if debugMode {
log.Println("Starting service WITHOUT TLS") log.Println("Starting service WITHOUT TLS")
log.Fatal(router.Run("localhost:8080")) log.Fatal(router.Run("localhost:8080"))
} else { } else {