From a30013d968177b1ea1f196fe15f7f2e65c8cd1d2 Mon Sep 17 00:00:00 2001 From: Quinten Date: Fri, 9 Feb 2024 09:50:06 +0100 Subject: [PATCH] Add version print and make emptying a value work --- README.md | 17 ++++++++++++++++- main.go | 11 +++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a6867b0..e09f474 100644 --- a/README.md +++ b/README.md @@ -78,4 +78,19 @@ If you want to support my work: | RCONEnabled | RCON_ENABLE | ✅ | | bUseAuth | USE_AUTH | | | BanListURL | BAN_LIST_URL | | -| Region | SERVER_REGION | | +| Region | SERVER_REGION | | + + +# Notes + +- If a variable does not exits the parser will not try to change that value in the configuration file. +- If you want to clear / empty a value in the config then you must set the ENV variable to `nil`or `null`, putting just an empty variable will not edit the value in the config. +- There is some very basic validation on the variables. + +|Rule|Value|Example| +|-----|-----|-----| +|Numeric|Allows only positive numeric values|"123" or "25565"| +|Floating|Allows only positive floating-point values|"0.005" or "3.14"| +|TrueFalse| Allows values "True" or "False"|True" or "False"| +|String|Everything|"this is a test" or "test"| +|AlphaDash|Allows only alphanumeric characters and dashes|"abc123" or"test-123"| diff --git a/main.go b/main.go index bb57206..c3f014f 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,11 @@ import ( "regexp" ) -func main() { +// Version of the program +const Version = "v1.0.7" +func main() { + fmt.Println("Program Version:", Version) // ValidationRules holds validation rules for environment variables var ValidationRules = map[string]func(string) bool{ "Numeric": func(val string) bool { @@ -257,14 +260,14 @@ func main() { // Update values based on environment variables for key, value := range envVars { // Check if the environment variable exists - if value == "" && os.Getenv(key) == "" && os.Getenv(key) != "nil"{ + if value == "" && os.Getenv(key) == ""{ //fmt.Printf("Skipping key: %s because environment variable doesn't exist\n", key) continue } // Skip validation and updating if value is empty but environment variable exists - if value == "" && (os.Getenv(key) != "" || os.Getenv(key) == "nil") { - fmt.Printf("Skipping key: %s because value is empty\n", key) + if value == "nil" || value == "null" { + fmt.Printf("Cleared key %s due to %s value.\n", key, value) // Set key to empty value in the INI file setINIValue(&iniContent, key, "", envVarsQuotes[key]) continue