NeoZephyr / Post-It-Note

0 stars 0 forks source link

GO 事务处理 #21

Open NeoZephyr opened 2 years ago

NeoZephyr commented 2 years ago
if tx, err = dao.BeginTran(c); err != nil {
    err = errors.Wrapf(err, "dao.BeginTran(%d)", mid)
    return
}

defer func() {
    if err != nil {
        if err1 := tx.Rollback(); err1 != nil {
            err = errors.Wrapf(err, "tx.Rollback(%d)", mid)
        }
        return
    }
    if err = tx.Commit(); err != nil {
        err = errors.Wrapf(err, "tx.Commit(%d)", mid)
    }
}()