4 ms·
How painful does this look? func action(...) (err error) { tx, err := db.Begin() if err != nil { return fmt.Errorf("preparing t
by AYBABTME 12y ago
How painful does this look?
func action(...) (err error) {
tx, err := db.Begin()
if err != nil {
return fmt.Errorf("preparing transaction: %v", err)
}
defer func(tx *sql.Tx) {
if err != nil {
_ = tx.Rollback()
} else {
err = tx.Commit()
}
}(tx)
// do something
return
}