BrainMinder/internal/env/env.go

44 lines
626 B
Go
Raw Normal View History

2024-08-22 10:13:16 +02:00
package env
import (
"os"
"strconv"
)
func GetString(key, defaultValue string) string {
value, exists := os.LookupEnv(key)
if !exists {
return defaultValue
}
return value
}
func GetInt(key string, defaultValue int) int {
value, exists := os.LookupEnv(key)
if !exists {
return defaultValue
}
intValue, err := strconv.Atoi(value)
if err != nil {
panic(err)
}
return intValue
}
func GetBool(key string, defaultValue bool) bool {
value, exists := os.LookupEnv(key)
if !exists {
return defaultValue
}
boolValue, err := strconv.ParseBool(value)
if err != nil {
panic(err)
}
return boolValue
}