When a user registers, my app does two things - it adds the user to the database and it sends a verification email:
...
err := collection("users").Insert(&u);
if err != nil {
WriteServerError(w, err)
return
}
if err = sendVerificationEmail(&u); err != nil {
WriteServerError(w, err)
}
...
I wouldn't want to add the user to the database if the email does not get sent nor would I want to send the email if the user didn't get added to the database (the latter is of course taken care of with the code blocks in this order).
Assuming Go supports transactions, is it worth bothering with for something like this? If so then could someone give me some pointers as to how I would convert this code above?
I could use nested statements but this could get very ugly.