tlm-login-server/internal/config/initialize.go

71 lines
1.6 KiB
Go

package config
import (
"errors"
"fmt"
"os"
"strconv"
)
func InitializeConfig() error {
if os.Getenv("TLM_SQLITE_PATH") != "" {
SQLitePath = os.Getenv("TLM_SQLITE_PATH")
} else {
return errors.New("required env var is empty: TLM_SQLITE_PATH")
}
if os.Getenv("TLM_SMTP_FROM") != "" {
SMTPFrom = os.Getenv("TLM_SMTP_FROM")
} else {
return errors.New("required env var is empty: TLM_SMTP_FROM")
}
if os.Getenv("TLM_SMTP_SERVER") != "" {
SMTPServer = os.Getenv("TLM_SMTP_SERVER")
} else {
return errors.New("required env var is empty: TLM_SMTP_SERVER")
}
if os.Getenv("TLM_SMTP_USER") != "" {
SMTPUser = os.Getenv("TLM_SMTP_USER")
} else {
return errors.New("required env var is empty: TLM_SMTP_USER")
}
if os.Getenv("TLM_SMTP_PASSWORD") != "" {
SMTPPassword = os.Getenv("TLM_SMTP_PASSWORD")
} else {
return errors.New("required env var is empty: TLM_SMTP_PASSWORD")
}
if os.Getenv("TLM_BASEPATH") != "" {
BasePath = os.Getenv("TLM_BASEPATH")
} else {
return errors.New("required env var is empty: TLM_BASEPATH")
}
if os.Getenv("TLM_SMTP_VERIFYSSL") != "" {
var err error
SMTPVerifySSL, err = strconv.ParseBool(os.Getenv("TLM_SMTP_VERIFYSSL"))
if err != nil {
return errors.New(fmt.Sprintf("Invalid value for env var TLM_SMTP_VERIFYSSL: %v",
os.Getenv("TLM_SMTP_VERIFYSSL")))
}
} else {
SMTPVerifySSL = true
}
if os.Getenv("TLM_SMTP_PORT") != "" {
var err error
SMTPPort, err = strconv.Atoi(os.Getenv("TLM_SMTP_PORT"))
if err != nil {
return errors.New(fmt.Sprintf("Invalid value for env var TLM_SMTP_PORT: %v",
os.Getenv("TLM_SMTP_PORT")))
}
} else {
SMTPPort = 465
}
return nil
}