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 (
"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 {