This commit is contained in:
+27
-9
@@ -10,12 +10,13 @@ import (
|
||||
)
|
||||
|
||||
type config struct {
|
||||
dsn string
|
||||
environment string
|
||||
webBaseURL string
|
||||
json bool
|
||||
yes bool
|
||||
mail mailer.Config
|
||||
dsn string
|
||||
environment string
|
||||
webBaseURL string
|
||||
demoResetEnabled bool
|
||||
json bool
|
||||
yes bool
|
||||
mail mailer.Config
|
||||
}
|
||||
|
||||
func configFromEnvironment() (config, error) {
|
||||
@@ -23,11 +24,16 @@ func configFromEnvironment() (config, error) {
|
||||
if err != nil {
|
||||
return config{}, err
|
||||
}
|
||||
demoResetEnabled, err := envBool("GARDOMATIC_DEMO_RESET_ENABLED", false)
|
||||
if err != nil {
|
||||
return config{}, err
|
||||
}
|
||||
|
||||
return config{
|
||||
dsn: os.Getenv("GARDOMATIC_DB_DSN"),
|
||||
environment: envString("GARDOMATIC_ENV", "development"),
|
||||
webBaseURL: envString("GARDOMATIC_WEB_BASE_URL", "http://localhost:4040"),
|
||||
dsn: os.Getenv("GARDOMATIC_DB_DSN"),
|
||||
environment: envString("GARDOMATIC_ENV", "development"),
|
||||
webBaseURL: envString("GARDOMATIC_WEB_BASE_URL", "http://localhost:4040"),
|
||||
demoResetEnabled: demoResetEnabled,
|
||||
mail: mailer.Config{
|
||||
Mode: mailer.Mode(envString("GARDOMATIC_SMTP_MODE", string(mailer.ModeFile))),
|
||||
Host: os.Getenv("GARDOMATIC_SMTP_HOST"),
|
||||
@@ -40,6 +46,18 @@ func configFromEnvironment() (config, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func envBool(name string, fallback bool) (bool, error) {
|
||||
value := strings.TrimSpace(os.Getenv(name))
|
||||
if value == "" {
|
||||
return fallback, nil
|
||||
}
|
||||
b, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("%s must be a boolean: %w", name, err)
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func envString(name, fallback string) string {
|
||||
if value := strings.TrimSpace(os.Getenv(name)); value != "" {
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user