2024-11-08 15:00:17 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Env(name string, out any, def string) {
|
|
|
|
raw := os.Getenv(name)
|
|
|
|
if raw == "" {
|
|
|
|
raw = def
|
|
|
|
log.Printf("No \"%s\" provided, defaulting to \"%s\".", name, def)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch value := out.(type) {
|
|
|
|
case *int:
|
|
|
|
i, err := strconv.ParseInt(raw, 10, 64)
|
|
|
|
if err != nil {
|
2024-11-08 15:11:57 +00:00
|
|
|
log.Printf("\"%s\" is not a number (\"%s\").", name, raw)
|
2024-11-08 15:00:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = int(i)
|
|
|
|
|
|
|
|
case *bool:
|
|
|
|
switch raw {
|
|
|
|
case "true", "TRUE", "1":
|
|
|
|
*value = true
|
|
|
|
case "false", "FALSE", "0":
|
|
|
|
*value = false
|
|
|
|
}
|
|
|
|
|
|
|
|
case *string:
|
|
|
|
*value = raw
|
|
|
|
}
|
|
|
|
}
|