xmid

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause-Clear Imports: 4 Imported by: 0

Documentation

Overview

自定义中间件处理依赖

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

执行事务处理的中间数据依赖

func Default

func Default() *Context

获取默认中间件事务支持 此事务已存在回滚事务和提交事务

func DefaultEmpty

func DefaultEmpty() *Context

获取一个空的中间事务支持

func (*Context) Abort

func (c *Context) Abort()

终止中间件的处理 此操作会终止中间件的执行,但是不会调用HookRollback钩子

func (*Context) AbortWithError

func (c *Context) AbortWithError(err error)

携带错误信息终止中间件的处理,但是不会调用HookCommit钩子

err	携带的错误信息

func (*Context) Error added in v0.3.7

func (c *Context) Error() error

获取其中的错误信息

func (*Context) GetDB

func (c *Context) GetDB() (*gorm.DB, error)

获取事务处理的数据库连接[等同于调用c.GetDBS("default")]

func (*Context) GetDBS

func (c *Context) GetDBS(key string) (*gorm.DB, error)

获取事务处理的数据库连接

key	数据库下标,多数据库连接时使用

func (*Context) GetOth

func (c *Context) GetOth(key string) (any, error)

获取使用过程中需要调用的一些其他数据

key	待获取的数据下标

func (*Context) HookCommit

func (c *Context) HookCommit(h ...HandlerFunc) *Context

未发生错误时的提交钩子

h	提交时调用的函数

func (*Context) HookEnd

func (c *Context) HookEnd(h ...HandlerFunc) *Context

运行结束时的钩子

h	运行结束时调用的函数

func (*Context) HookRollback

func (c *Context) HookRollback(h ...HandlerFunc) *Context

发生错误时的回退钩子

h	发生错误时调用的函数

func (*Context) HookStart

func (c *Context) HookStart(h ...HandlerFunc) *Context

开始运行时的钩子

h	开始运行时调用的函数

func (*Context) Next

func (c *Context) Next()

执行下一个中间件

func (*Context) Run

func (c *Context) Run(h HandlerFunc) error

执行运行结果

h	待运行函数

func (*Context) SetDB

func (c *Context) SetDB(db *gorm.DB)

设置DB 中间件事务处理时使用[等同于调用c.SetDBS("default",xxx)]

db	待设置的数据库连接

func (*Context) SetDBS

func (c *Context) SetDBS(key string, db *gorm.DB)

设置DB 中间件事务处理时使用

key	数据库下标,多数据库连接时使用
db	待设置的数据库连接

func (*Context) SetOth

func (c *Context) SetOth(key string, val any)

设置使用过程中需要调用的一些其他数据

key	待设置的数据下标
val	待设置的数据值

func (*Context) Use

func (c *Context) Use(h ...HandlerFunc) *Context

添加中间件支持

h	中间件处理过程

type HandlerFunc

type HandlerFunc func(*Context)

中间件需要传入的函数体

func DbTool added in v0.3.7

func DbTool(dbs string, f func(d *gorm.DB, c *Context) error) HandlerFunc

直接进行数据库操作

dbs	操作的数据库下标,使用SetDB进行设置
f	操作的函数标识,该函数会传入db和ctx进行协助处理

func DbToolDefault added in v0.3.7

func DbToolDefault(f func(d *gorm.DB, c *Context) error) HandlerFunc

直接进行数据库操作

f	操作的函数标识,该函数会传入db和ctx进行协助处理

Jump to

Keyboard shortcuts

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