initial commit

This commit is contained in:
Jonas Leder 2025-03-18 19:18:12 +01:00
commit c7333f3762
5 changed files with 138 additions and 0 deletions

37
config/config.go Normal file
View file

@ -0,0 +1,37 @@
package config
import (
"errors"
"os"
logger "log"
"jonasled.dev/jonasled/go-libs/log"
)
func GetOrDefault(configName string, defaultVal string) string {
if os.Getenv(configName) != "" {
return os.Getenv(configName)
}
return defaultVal
}
func GetOrError(configName string) (string, error) {
if os.Getenv(configName) != "" {
return os.Getenv(configName), nil
}
return "", errors.New("Config " + configName + " not found")
}
func GetOrFatal(configName string) string {
if os.Getenv(configName) != "" {
return os.Getenv(configName)
}
if log.Log != nil { // if logrus is already setup, use logrus
log.Log.Fatal("Required config key ", configName, " not found")
return ""
}
logger.Fatal("Required config key ", configName, " not found")
return ""
}