refac: runtime settings are read once at startup and passed in through the composition root; no handler, router or repository reads environment variables

This commit is contained in:
fsylvain committed 2026-09-24 01:30:00 +02:00
1 parent e474f03d91
commit 0b4e614ec9
15 files changed
+722 -66

No files matched your search

@@ -2,30 +2,31 @@ package mailer
import (
domain "RenewCMS/internal/domain/mail"
"RenewCMS/internal/infrastructure/config"
"bytes"
"embed"
"html/template"
"log"
"os"
"strconv"
"gopkg.in/gomail.v2"
)
type MailRepository struct{}
type MailRepository struct {
smtp config.SmtpSettings
}
//go:embed templates/*
var mailTemplateFiles embed.FS
func NewMailRepository() *MailRepository {
return &MailRepository{}
func NewMailRepository(smtp config.SmtpSettings) *MailRepository {
return &MailRepository{smtp: smtp}
}
func (m MailRepository) Send(receiverAddress string, templateName string, data any) error {
from := os.Getenv("SMTP_EMAIL")
password := os.Getenv("SMTP_PASSWORD")
smtpHost := os.Getenv("SMTP_HOST")
smtpPort, _ := strconv.Atoi(os.Getenv("SMTP_PORT"))
from := m.smtp.Email
password := m.smtp.Password
smtpHost := m.smtp.Host
smtpPort := m.smtp.Port
d := gomail.NewDialer(smtpHost, smtpPort, from, password)