fog/internal/env/env.go

32 lines
510 B
Go
Raw Normal View History

2024-12-30 06:29:34 +00:00
package env
import (
"log"
"os"
"strconv"
)
func GetString(key, fallback string) string {
val, ok := os.LookupEnv(key)
if !ok {
return fallback
}
return val
}
func GetInt(key string, fallback int) int {
val, ok := os.LookupEnv(key)
if !ok {
return fallback
}
valInt, err := strconv.Atoi(val)
if err != nil {
log.Printf("Failed to convert environment variable with key %s and value %s to int. Using fallback %d. (err: %s)", key, val, fallback, err)
return fallback
}
return valInt
}