Documentation ¶
Overview ¶
Example (PkgLevelTxFunctions) ¶
package main import ( "context" "github.com/adamluzsi/frameless/pkg/logger" "github.com/adamluzsi/frameless/pkg/txs" ) func MyActionWhichMutateTheSystemState(ctx context.Context) error { return nil } func RollbackForMyActionWhichMutatedTheSystemState(ctx context.Context) error { return nil } func MyUseCase(ctx context.Context) (returnErr error) { ctx, err := txs.Begin(ctx) if err != nil { return err } defer txs.Finish(&returnErr, ctx) if err := MyActionWhichMutateTheSystemState(ctx); err != nil { return err } txs.OnRollback(ctx, func(ctx context.Context) error { return RollbackForMyActionWhichMutatedTheSystemState(ctx) }) return nil } func main() { ctx := context.Background() ctx, err := txs.Begin(ctx) if err != nil { logger.Error(ctx, "error with my tx", logger.ErrField(err)) } if err := MyUseCase(ctx); err != nil { txs.Rollback(ctx) return } txs.Commit(ctx) }
Output:
Index ¶
- Constants
- func Begin(ctx context.Context) (context.Context, error)
- func Commit(ctx context.Context) error
- func Finish(returnError *error, tx context.Context)
- func OnRollback[StepFn onRollbackStepFn](ctx context.Context, step StepFn) error
- func Rollback(ctx context.Context) error
- type TxRollbackError
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func OnRollback ¶
Types ¶
type TxRollbackError ¶ added in v0.90.1
func (*TxRollbackError) Error ¶ added in v0.90.1
func (err *TxRollbackError) Error() string
func (*TxRollbackError) Unwrap ¶ added in v0.90.1
func (err *TxRollbackError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.