Fixed Bugs

* Fixed gin release mode
- Removed debug logs
This commit is contained in:
Daniel Legt 2024-01-21 22:56:53 +02:00
parent 39e16ce408
commit d7e856aca2
4 changed files with 19 additions and 11 deletions

View File

@ -23,3 +23,6 @@ LISTEN=":8080"
# Basic Security, these are required to view the data
IDENTITY_USERNAME=admin
IDENTITY_PASSWORD=admin
# Enable/Disable debug features
DEBUG_MODE=false

View File

@ -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
}

View File

@ -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{

View File

@ -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))