feat: added server and db config

This commit is contained in:
darwincereska
2025-12-20 21:17:49 -05:00
parent 59adb32e68
commit d7338f717b
7 changed files with 509 additions and 1 deletions

33
server/utils/env.go Normal file
View File

@@ -0,0 +1,33 @@
package utils
import (
"os"
"strconv"
)
// Gets value from environment or uses default value
func GetEnvOrDefault[T string | int | bool | float64](key string, defaultValue T) T {
value, exists := os.LookupEnv(key)
if !exists {
return defaultValue
}
// Handle conversion based on the type of defaultValue
switch any(defaultValue).(type) {
case string:
return any(value).(T)
case int:
if intValue, err := strconv.Atoi(value); err == nil {
return any(intValue).(T)
}
case bool:
if boolValue, err := strconv.ParseBool(value); err == nil {
return any(boolValue).(T)
}
case float64:
if floatValue, err := strconv.ParseFloat(value, 64); err == nil {
return any(floatValue).(T)
}
}
return defaultValue // return default value if conversion fails
}