32 lines
510 B
Go
32 lines
510 B
Go
|
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
|
||
|
}
|