Documentation
¶
Overview ¶
Package tx — лист транзакционных помощников движка. СОДЕРЖИМОЕ АПСТРИМНОЕ И ПЕРЕНЕСЕНО ДОСЛОВНО из `storage/transactional.go`; правка Kacho — только место.
ЗАЧЕМ ПЕРЕЕХАЛО. `handler/oauth2` импортировал пакет `storage` ради этих трёх помощников, живущих на чистой стандартной библиотеке. Весь вес пакета даёт СОСЕДНИЙ файл `storage/memory.go` — эталонное хранилище в памяти, нужное только примерам и пробам: оно импортирует `internal`, то есть моки gomock, и через них тащило gomock и testify в ПРОИЗВОДСТВЕННЫЙ граф сборки любого потребителя движка. Лист зависит ровно от `context` и ни от чего больше.
На прежнем месте (`storage.Transactional`, `storage.MaybeBeginTx`, `storage.MaybeCommitTx`, `storage.MaybeRollbackTx`) оставлены псевдонимы, чтобы чужой код и пробы апстрима продолжали компилироваться без правки.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaybeBeginTx ¶
MaybeBeginTx is a helper function that can be used to initiate a transaction if the supplied storage implements the `Transactional` interface.
func MaybeCommitTx ¶
MaybeCommitTx is a helper function that can be used to commit a transaction if the supplied storage implements the `Transactional` interface.
func MaybeRollbackTx ¶
MaybeRollbackTx is a helper function that can be used to rollback a transaction if the supplied storage implements the `Transactional` interface.
Types ¶
type Transactional ¶
type Transactional interface {
BeginTX(ctx context.Context) (context.Context, error)
Commit(ctx context.Context) error
Rollback(ctx context.Context) error
}
A storage provider that has support for transactions should implement this interface to ensure atomicity for certain flows that require transactional semantics. Fosite will call these methods (when atomicity is required) if and only if the storage provider has implemented `Transactional`. It is expected that the storage provider will examine context for an existing transaction each time a database operation is to be performed.
An implementation of `BeginTX` should attempt to initiate a new transaction and store that under a unique key in the context that can be accessible by `Commit` and `Rollback`. The "transactional aware" context will then be returned for further propagation, eventually to be consumed by `Commit` or `Rollback` to finish the transaction.
Implementations for `Commit` & `Rollback` should look for the transaction object inside the supplied context using the same key used by `BeginTX`. If these methods have been called, it is expected that a txn object should be available in the provided context.