/* * Copyright (C) 2023 Jonni Liljamo * * This file is licensed under AGPL-3.0-or-later, see NOTICE and LICENSE for * more information. */ package util import ( "log" "os" "strconv" ) func LoadVar(key string, def string) string { value, found := os.LookupEnv(key) if found { return value } if def == "" { log.Fatalf("[tixe/util] Environment variable %s is empty, and has no default!", key) } else { log.Printf("[tixe/util] Environment variable %s is empty, using default '%s'", key, def) } return def } func LoadVarBool(key string, def bool) bool { value, found := os.LookupEnv(key) if found { res, err := strconv.ParseBool(value) if err != nil { log.Fatalf("[tixe/util] Environment variable %s failed to parse to bool from '%s'", key, value) } return res } log.Printf("[tixe/util] Environment variable %s is empty, using default '%t'", key, def) return def }