mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-06 13:39:41 +01:00
chore: update helper func to check env with prefix or suffix for multi backups
Some checks failed
Build / docker (push) Failing after 14m58s
Some checks failed
Build / docker (push) Failing after 14m58s
This commit is contained in:
@@ -145,15 +145,26 @@ func getDatabase(database Database) *dbConfig {
|
|||||||
|
|
||||||
// Helper function to get environment variable or use a default value
|
// Helper function to get environment variable or use a default value
|
||||||
func getEnvOrDefault(currentValue, envKey, suffix, defaultValue string) string {
|
func getEnvOrDefault(currentValue, envKey, suffix, defaultValue string) string {
|
||||||
|
// Return the current value if it's already set
|
||||||
if currentValue != "" {
|
if currentValue != "" {
|
||||||
return currentValue
|
return currentValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for suffixed or prefixed environment variables if a suffix is provided
|
||||||
if suffix != "" {
|
if suffix != "" {
|
||||||
envSuffix := os.Getenv(fmt.Sprintf("%s_%s", envKey, strings.ToUpper(suffix)))
|
suffixUpper := strings.ToUpper(suffix)
|
||||||
|
envSuffix := os.Getenv(fmt.Sprintf("%s_%s", envKey, suffixUpper))
|
||||||
if envSuffix != "" {
|
if envSuffix != "" {
|
||||||
return envSuffix
|
return envSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
envPrefix := os.Getenv(fmt.Sprintf("%s_%s", suffixUpper, envKey))
|
||||||
|
if envPrefix != "" {
|
||||||
|
return envPrefix
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fall back to the default value using a helper function
|
||||||
return utils.EnvWithDefault(envKey, defaultValue)
|
return utils.EnvWithDefault(envKey, defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user