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

54 lines
1.2 KiB
Go
Raw Normal View History

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_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
}