feat: 新增 WithSilent/WithRolesScope 写操作选项
WithSilent 让写操作跳过变更通知(ResChangeEventFunc/ResWatcher),权限过滤/字段脱敏不受影响,用于类似"记录登录 IP"这种高频写但不需要广播"资源变了"的场景,避免不必要的缓存刷新。 WithRolesScope 显式指定权限过滤范围(ResScopeOn/All 才按角色过滤,Off 或不传都跳过),替代原来一直没接线生效的 Access 选项。两个选项相互独立,可以单独用也可以一起用。
This commit is contained in:
Executable
+52
@@ -0,0 +1,52 @@
|
||||
package req
|
||||
|
||||
import "git.fsdpf.net/go/db"
|
||||
|
||||
type ResOptions struct {
|
||||
Tx *db.TxDatabase
|
||||
Alias string
|
||||
Silent bool
|
||||
// RolesScope 默认零值 ResScopeOff:不传 WithRolesScope,或显式传 ResScopeOff,都表示跳过
|
||||
// 权限过滤;只有显式传 ResScopeOn/ResScopeAll 才会按角色过滤。
|
||||
RolesScope ResScope
|
||||
}
|
||||
|
||||
type ResOption func(p *ResOptions)
|
||||
|
||||
func WithTx(tx *db.TxDatabase) ResOption {
|
||||
return func(p *ResOptions) {
|
||||
p.Tx = tx
|
||||
}
|
||||
}
|
||||
|
||||
func WithAlias(as string) ResOption {
|
||||
return func(p *ResOptions) {
|
||||
p.Alias = as
|
||||
}
|
||||
}
|
||||
|
||||
// WithSilent 让这次写操作跳过变更通知(ResChangeEventFunc/ResWatcher),权限过滤、字段脱敏、
|
||||
// 字段规范化、类型转换、默认值填充等都不受影响。用于类似"记录登录 IP"这种高频写、但不需要广播
|
||||
// "资源变了"的场景,避免不必要的缓存刷新/watcher 触发。
|
||||
func WithSilent() ResOption {
|
||||
return func(p *ResOptions) {
|
||||
p.Silent = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithRolesScope 显式指定这次写/查操作的权限过滤范围。ResScopeOn/ResScopeAll 按角色过滤
|
||||
// (行级 WHERE 注入、字段级读脱敏、字段级写权限);ResScopeOff(或不调用这个 option)跳过
|
||||
// 权限过滤,变更通知、字段规范化、类型转换、默认值填充等不受影响。
|
||||
func WithRolesScope(s ResScope) ResOption {
|
||||
return func(p *ResOptions) {
|
||||
p.RolesScope = s
|
||||
}
|
||||
}
|
||||
|
||||
type gParamsOpt func(g *gparams)
|
||||
|
||||
func Session(session string) gParamsOpt {
|
||||
return func(g *gparams) {
|
||||
g.session = session
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user