This commit is contained in:
lbenedar
2026-03-19 18:19:37 +03:00
parent 86ce8e9eec
commit 8504d0e5ba
5 changed files with 95 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import (
"gitea.local.lab/Lbenedar/greenlight/internal/data"
"gitea.local.lab/Lbenedar/greenlight/internal/jsonlog"
"gitea.local.lab/Lbenedar/greenlight/internal/mailer"
_ "github.com/lib/pq"
)
@@ -18,6 +19,7 @@ type application struct {
config config
logger *jsonlog.Logger
models data.Models
mailer mailer.Mailer
}
type config struct {
@@ -34,6 +36,13 @@ type config struct {
burst int
enabled bool
}
smtp struct {
host string
port int
username string
password string
sender string
}
}
func openDB(cfg config) (*sql.DB, error) {
@@ -76,6 +85,12 @@ func main() {
flag.IntVar(&cfg.limiter.burst, "limiter-burst", 4, "Rate limiter maximum burst")
flag.BoolVar(&cfg.limiter.enabled, "limiter-enabled", true, "Enable rate limiter")
flag.StringVar(&cfg.smtp.host, "smtp-host", "smtp.mailtrap.io", "SMTP host")
flag.IntVar(&cfg.smtp.port, "smtp-port", 25, "SMTP port")
flag.StringVar(&cfg.smtp.username, "smtp-username", "0abf276416b183", "SMTP username")
flag.StringVar(&cfg.smtp.password, "smtp-password", "d8672aa2264bb5", "SMTP password")
flag.StringVar(&cfg.smtp.sender, "smtp-sender", "Greenlight <no-reply@greenlight.net", "SMTP sender")
flag.Parse()
logger := jsonlog.New(os.Stdout, jsonlog.LevelInfo)
@@ -92,6 +107,7 @@ func main() {
config: cfg,
logger: logger,
models: data.NewModels(db),
mailer: mailer.New(cfg.smtp.host, cfg.smtp.port, cfg.smtp.username, cfg.smtp.password, cfg.smtp.sender),
}
err = app.serve()

View File

@@ -52,6 +52,12 @@ func (app *application) registerUserHandler(w http.ResponseWriter, r *http.Reque
return
}
// err = app.mailer.Send(user.Email, "user_welcome.tmpl", user)
// if err != nil {
// app.serverErrorResponse(w, r, err)
// return
// }
err = app.writeJSON(w, http.StatusCreated, envelope{"user": user}, nil)
if err != nil {
app.serverErrorResponse(w, r, err)