From d7e856aca257d804b628ec6281c6de2c3ce32058 Mon Sep 17 00:00:00 2001 From: Daniel Legt Date: Sun, 21 Jan 2024 22:56:53 +0200 Subject: [PATCH] Fixed Bugs * Fixed gin release mode - Removed debug logs --- .env.example | 5 ++++- lib/config/config.go | 8 ++++++++ lib/web/api.go | 6 ------ lib/web/net.go | 11 +++++++---- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 4aaea2b..adf97ea 100644 --- a/.env.example +++ b/.env.example @@ -22,4 +22,7 @@ LISTEN=":8080" # Basic Security, these are required to view the data IDENTITY_USERNAME=admin -IDENTITY_PASSWORD=admin \ No newline at end of file +IDENTITY_PASSWORD=admin + +# Enable/Disable debug features +DEBUG_MODE=false \ No newline at end of file diff --git a/lib/config/config.go b/lib/config/config.go index 0226b2d..fa049a7 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -16,6 +16,8 @@ type DHConfig struct { IdentityUsername string `json:"identityUsername"` IdentityPassword string `json:"identityPassword"` + + DebugMode bool `json:"debugMode"` } func GetConfiguration() DHConfig { @@ -64,5 +66,11 @@ func GetConfiguration() DHConfig { config.IdentityPassword = val } + if val, exists := os.LookupEnv("DEBUG_MODE"); exists { + if isDebug, err := strconv.ParseBool(val); err == nil { + config.DebugMode = isDebug + } + } + return config } diff --git a/lib/web/api.go b/lib/web/api.go index 36a4887..ac847cb 100644 --- a/lib/web/api.go +++ b/lib/web/api.go @@ -1,7 +1,6 @@ package web import ( - "fmt" "net/http" "strconv" "time" @@ -30,7 +29,6 @@ func setupApi(r *gin.Engine) { var olderThan, newerThan *time.Time if ot := ctx.Query("older"); ot != "" { - fmt.Printf("ot = %s\n", ot) if otInt, err := strconv.ParseInt(ot, 10, 64); err == nil { otTime := time.UnixMilli(otInt) olderThan = &otTime @@ -38,16 +36,12 @@ func setupApi(r *gin.Engine) { } if nt := ctx.Query("newer"); nt != "" { - fmt.Printf("nt = %s\n", nt) if ntInt, err := strconv.ParseInt(nt, 10, 64); err == nil { ntTime := time.UnixMilli(ntInt) newerThan = &ntTime } } - fmt.Printf("olderThan = %s\n", olderThan) - fmt.Printf("newerThan = %s\n", newerThan) - graphData, err := svc.GetDiskGraphImage(diskId, newerThan, olderThan) if err != nil { ctx.AbortWithStatusJSON(500, gin.H{ diff --git a/lib/web/net.go b/lib/web/net.go index c598268..ef1b1cb 100644 --- a/lib/web/net.go +++ b/lib/web/net.go @@ -6,12 +6,15 @@ import ( ) func SetupRouter() *gin.Engine { - // Initialize the Gin engine cfg := config.GetConfiguration() - r := gin.Default() - // Set gin to release - gin.SetMode(gin.ReleaseMode) + if !cfg.DebugMode { + // Set gin to release + gin.SetMode(gin.ReleaseMode) + } + + // Initialize the Gin engine + r := gin.Default() r.Use(BasicAuthMiddleware(cfg.IdentityUsername, cfg.IdentityPassword))