package envkit import ( "os" "strconv" ) // String returns the environment variable key, or fallback if unset/empty. // Same semantics as the getenv() helper every cmd/server/main.go in the // monolith defined locally — hoisted here once since every microservice // now needs it. func String(key, fallback string) string { if v := os.Getenv(key); v != "" { return v } return fallback } // Int parses the environment variable key as an integer, or returns // fallback if unset or unparseable. func Int(key string, fallback int) int { v := os.Getenv(key) if v == "" { return fallback } n, err := strconv.Atoi(v) if err != nil { return fallback } return n } // Float parses the environment variable key as a float64, or returns // fallback if unset or unparseable. func Float(key string, fallback float64) float64 { v := os.Getenv(key) if v == "" { return fallback } f, err := strconv.ParseFloat(v, 64) if err != nil { return fallback } return f } // Bool parses the environment variable key as a bool ("true"/"1"/"yes", // case-insensitive, or their opposites), or returns fallback if unset // or unparseable. func Bool(key string, fallback bool) bool { v := os.Getenv(key) if v == "" { return fallback } b, err := strconv.ParseBool(v) if err != nil { return fallback } return b }