initial commit
This commit is contained in:
commit
c7333f3762
5 changed files with 138 additions and 0 deletions
37
config/config.go
Normal file
37
config/config.go
Normal 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 ""
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue