Added greater granularity for boolean environment variables (#511)

* Added greater granularity for boolean environment variables

* Improved solution as reviewed
This commit is contained in:
Alessandro Detta
2024-02-22 11:35:53 +01:00
committed by GitHub
parent 3d7f907a33
commit b5bed10571
7 changed files with 73 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"regexp"
"slices"
"strings"
"github.com/gin-gonic/gin"
@@ -116,3 +117,13 @@ func GetQueryProps(c *gin.Context) (*QueryProps, error) {
return &qp, nil
}
func EnvAsBool(envKey string, envDef bool) bool {
validSettableValues := []string{"false", "true", "0", "1"}
envValue := os.Getenv(envKey)
if slices.Contains(validSettableValues, envValue) {
return envValue == "true" || envValue == "1"
} else {
return envDef
}
}