37 lines
777 B
Go
37 lines
777 B
Go
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 ""
|
|
|
|
}
|