This commit is contained in:
lbenedar
2026-03-19 18:30:21 +03:00
parent 8504d0e5ba
commit 46a1bb868b
2 changed files with 17 additions and 5 deletions

View File

@@ -120,3 +120,14 @@ func (app *application) readInt(qs url.Values, key string, defaultValue int, v *
}
return i
}
func (app *application) background(fn func()) {
go func() {
defer func() {
if err := recover(); err != nil {
app.logger.PrintError(fmt.Errorf("%s", err), nil)
}
}()
fn()
}()
}

View File

@@ -52,11 +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
// }
app.background(func() {
err = app.mailer.Send(user.Email, "user_welcome.tmpl", user)
if err != nil {
app.logger.PrintError(err, nil)
}
})
err = app.writeJSON(w, http.StatusCreated, envelope{"user": user}, nil)
if err != nil {