Documentation
¶
Index ¶
- func ExtractTopLevelField(fieldPath string) string
- func GetAllReferencedFields(fieldPaths []string) []string
- func GetFieldPathDepth(fieldPath string) int
- func GetNestedField(data interface{}, fieldPath string) (interface{}, bool)
- func IsNestedField(fieldName string) bool
- func NormalizeFieldPath(fieldPath string) string
- func SetNestedField(data map[string]interface{}, fieldPath string, value interface{}) error
- func ValidateFieldPath(fieldPath string) error
- type FieldAccessError
- type FieldAccessor
- type FieldPart
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractTopLevelField ¶
ExtractTopLevelField 从嵌套字段路径中提取顶级字段名 例如:"device.info.name" 返回 "device"
"data[0].name" 返回 "data" "a.b[0].c['key']" 返回 "a"
func GetAllReferencedFields ¶
GetAllReferencedFields 获取嵌套字段路径中引用的所有顶级字段 例如:["device.info.name", "sensor.temperature", "data[0].value"] 返回 ["device", "sensor", "data"]
func GetNestedField ¶
GetNestedField 从嵌套的map或结构体中获取字段值 支持点号分隔的字段路径、数组索引、Map键等复杂操作 支持的格式: - "device.info.name" (嵌套字段) - "data[0]" (数组索引) - "users[0].name" (数组元素的字段) - "config['key']" (字符串键) - "items[0][1]" (多维数组) - "nested.data[0].field['key']" (混合访问)
func NormalizeFieldPath ¶
NormalizeFieldPath 规范化字段路径格式
func SetNestedField ¶
SetNestedField 在嵌套的map中设置字段值,支持复杂路径 如果路径中的某些层级不存在,会自动创建
func ValidateFieldPath ¶
ValidateFieldPath 验证字段路径的格式是否正确
Types ¶
type FieldAccessError ¶
FieldAccessError 字段访问错误
func (*FieldAccessError) Error ¶
func (e *FieldAccessError) Error() string
type FieldAccessor ¶
type FieldAccessor struct {
Parts []FieldPart
}
FieldAccessor 字段访问器结构,用于解析复杂的字段路径
func ParseFieldPath ¶
func ParseFieldPath(fieldPath string) (*FieldAccessor, error)
ParseFieldPath 解析字段路径,支持点号、数组索引、Map键等复杂访问 支持的格式: - a.b.c (嵌套字段) - a.b[0] (数组索引) - a.b[0].c (数组元素的字段) - a.b["key"] (字符串键) - a.b['key'] (字符串键) - a.b[123] (数字键或数组索引) - a[0].b[1].c["key"] (混合访问)