44 lines
626 B
Go
44 lines
626 B
Go
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
|
|
}
|