aop

package
v0.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

README

切面方法

SetTransactional|事务传播

SetTransactional 中会根据传入的 context 中是否已经开启事务来决定当前函数返回的 teardown 中是否提交事务, 无需调用者关注.

当程序panic时, 事务回滚.

因为Go一般使用err作为错误返回, 所以增加: 根据 handler 传入err判断, 当 err!=nil 时回滚.

调用者只需在需要开启事务传播的位置插入以下代码即可, 需要传入 数据库连接db 和 上下文 ctx

ctx, transHandler, tx, err := SetTransactional(ctx, db)
if err != nil {
	return err
}
defer transHandler(&err)

Documentation

Index

Constants

View Source
const (
	Transaction = "transaction"
)

常量定义

Variables

View Source
var (
	TransactionUnformat    = "transaction_unformat"
	TransactionUnformatErr = &errors.Error{Code: TransactionUnformat, Msg: TransactionUnformat}
)

错误类型常量定义

Functions

func SetTransactional

func SetTransactional(ctx context.Context, db *database.DB) (
	newCtx context.Context, transHandler func(*error), tx *database.DB, err error)

SetTransactional 设置事务传播. 后续开发参照 Java/Spring @Transactional 注解 的理念

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL