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 ¶
IgnoreTenantContext 将跳过租户隔离标记注入 Context,允许全局访问数据
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
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 拦截更新操作,追加严格租户隔离写屏障
Click to show internal directories.
Click to hide internal directories.