Skip to content

Commit

Permalink
Add version print and make emptying a value work
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenQVD0 committed Feb 9, 2024
1 parent b175dae commit a30013d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"|
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a30013d

Please sign in to comment.