新增 resx 包剩余实现:字段/查询字段/脱敏/变更行等类型及测试

res_field.go/res_field_option.go(字段定义)、res_query_field.go/res_query_field_option.go(查询字段)、res_change_row.go(变更行)、res_mask_field.go(字段脱敏标记)及对应测试文件,配合此前已提交的 resource.go/res_interceptor.go 组成完整的 resx 资源实现包。
This commit is contained in:
2026-07-22 09:11:50 +08:00
parent 1868c8dd15
commit 09f4c40d67
10 changed files with 2427 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
package resx
import "git.fsdpf.net/go/req"
// ResFieldOption 是 NewResField 的选项函数类型。
type ResFieldOption func(*ResField)
// FieldWithUuid 设置字段的 uuid,不设置默认是 codeResource+code。
func FieldWithUuid(v string) ResFieldOption {
return func(f *ResField) { f.uuid = v }
}
// FieldWithName 设置字段的显示名称,不设置默认等于 code。
func FieldWithName(v string) ResFieldOption {
return func(f *ResField) { f.name = v }
}
// FieldWithDataType 设置字段的数据类型。
func FieldWithDataType(v req.ResDataType) ResFieldOption {
return func(f *ResField) { f.dataType = v }
}
// FieldWithLength 设置字段的长度/精度配置(含义因 DataType 而异,见 ToBlueprint)。
func FieldWithLength(v string) ResFieldOption {
return func(f *ResField) { f.length = v }
}
// FieldWithComment 设置字段的数据库列注释。
func FieldWithComment(v string) ResFieldOption {
return func(f *ResField) { f.comment = v }
}
// FieldWithDefault 设置字段的默认值原始配置("sql:xxx" 前缀表示 SQL 表达式,见 GetRawDefault)。
func FieldWithDefault(v string) ResFieldOption {
return func(f *ResField) { f.defaultValue = v }
}
// FieldWithVirtual 设置字段是否是虚拟列(VirtualAs)。
func FieldWithVirtual(v bool) ResFieldOption {
return func(f *ResField) { f.virtual = v }
}
// FieldWithVirtualExpr 设置虚拟列的表达式(仅在 FieldWithVirtual(true) 时有意义)。
func FieldWithVirtualExpr(v string) ResFieldOption {
return func(f *ResField) { f.virtualExpr = v }
}
// FieldWithRoles 设置"能读写该字段真实值"的角色列表,见 req.ResField.GetRoles 注释。
func FieldWithRoles(roles ...string) ResFieldOption {
return func(f *ResField) { f.roles = roles }
}