Sending background emails.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 2m54s
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 2m54s
This commit is contained in:
@@ -4,13 +4,14 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"greenlight.craftr.fr/internal/validator"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"greenlight.craftr.fr/internal/validator"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -204,3 +205,19 @@ func (app *application) readInt(qs url.Values, key string, defaultValue int, v *
|
||||
// Otherwise, return the converted integer value
|
||||
return i
|
||||
}
|
||||
|
||||
// Background: accepts an arbitrary function as a parameter
|
||||
func (app *application) background(fn func()) {
|
||||
// Launch a background goroutine
|
||||
go func() {
|
||||
// recover any panic.
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
app.logger.Error("%v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Execute the arbitrary function that we passed as the parameter
|
||||
fn()
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user