plugin

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IGNORE_TENANT_KEY 跳过租户隔离校验的 Context Key
	IGNORE_TENANT_KEY = "mongox:ignore_tenant"
)

Variables

This section is empty.

Functions

func IgnoreTenantContext

func IgnoreTenantContext(ctx context.Context) context.Context

IgnoreTenantContext 将跳过租户隔离标记注入 Context,允许全局访问数据

func IsIgnoreTenant

func IsIgnoreTenant(ctx context.Context) bool

IsIgnoreTenant 检查是否处于跳过隔离校验模式

Types

type AutoIDPlugin

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

AutoIDPlugin 自动为插入的文档分配全局唯一、单调递增的 ID。

单条插入:原子获取 1 个 ID 后立即注入文档。 批量插入:一次性原子申请 N 个连续 ID 后批量分发,消除 N 次串行网络往返。

func NewAutoIDPlugin

func NewAutoIDPlugin(db *mongo.Database) *AutoIDPlugin

NewAutoIDPlugin 实例化自增 ID 插件

func (*AutoIDPlugin) BeforeInsert

func (p *AutoIDPlugin) BeforeInsert(stmt *mongox.Statement) error

BeforeInsert 实现 BeforeInserter 接口,拦截写入,自动识别单条或批量切片并分配 ID

func (*AutoIDPlugin) Name

func (p *AutoIDPlugin) Name() string

Name 实现 Plugin 接口

type SharedConfig

type SharedConfig struct {
	IsShared  bool   // 是否为共享资源,允许跨租户或与系统租户共享
	IsPrivate bool   // 是否为纯私有资源,强制隔离
	IsIgnore  bool   // 是否为忽略模型,免除多租户插件的一切拦截
	Condition bson.M // 共享的附加过滤条件
}

SharedConfig 共享规则配置

type TenantOption

type TenantOption func(*TenantPlugin)

TenantOption 插件配置函数

func WithSystemTenantID

func WithSystemTenantID(id int64) TenantOption

WithSystemTenantID 设置自定义的系统根租户 ID

func WithTenantField

func WithTenantField(field string) TenantOption

WithTenantField 设置自定义的租户字段,默认 "tenant_id"

type TenantPlugin

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

TenantPlugin 自动在底层隔离多租户数据的插件

func NewTenantPlugin

func NewTenantPlugin(opts ...TenantOption) *TenantPlugin

NewTenantPlugin 实例化多租户隔离插件

func (*TenantPlugin) BeforeDelete

func (p *TenantPlugin) BeforeDelete(stmt *mongox.Statement) error

BeforeDelete 拦截删除操作,追加严格租户隔离写屏障

func (*TenantPlugin) BeforeFind

func (p *TenantPlugin) BeforeFind(stmt *mongox.Statement) error

BeforeFind 拦截查询操作,注入多租户安全边界

func (*TenantPlugin) BeforeInsert

func (p *TenantPlugin) BeforeInsert(stmt *mongox.Statement) error

BeforeInsert 拦截写入操作,反射安全填充当前租户 ID

func (*TenantPlugin) BeforeUpdate

func (p *TenantPlugin) BeforeUpdate(stmt *mongox.Statement) error

BeforeUpdate 拦截更新操作,追加严格租户隔离写屏障

func (*TenantPlugin) Name

func (p *TenantPlugin) Name() string

Name 实现 Plugin 接口

Jump to

Keyboard shortcuts

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