forked from mtusi2026/mtusi2026lab2
32 lines
508 B
Go
32 lines
508 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func GetEnv(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func ParseIntEnv(key string, fallback int) int {
|
|
v := GetEnv(key, "")
|
|
if v == "" {
|
|
return fallback
|
|
}
|
|
n, err := strconv.Atoi(v)
|
|
if err != nil {
|
|
return fallback
|
|
}
|
|
return n
|
|
}
|
|
|
|
func ParseDurationSecondsEnv(key string, fallbackSeconds int) time.Duration {
|
|
n := ParseIntEnv(key, fallbackSeconds)
|
|
return time.Duration(n) * time.Second
|
|
}
|