fieldpath

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTopLevelField

func ExtractTopLevelField(fieldPath string) string

ExtractTopLevelField extracts top-level field name from nested field path Examples: "device.info.name" returns "device"

"data[0].name" returns "data"
"a.b[0].c['key']" returns "a"

func GetAllReferencedFields

func GetAllReferencedFields(fieldPaths []string) []string

GetAllReferencedFields gets all top-level fields referenced in nested field paths Example: ["device.info.name", "sensor.temperature", "data[0].value"] returns ["device", "sensor", "data"]

func GetFieldPathDepth

func GetFieldPathDepth(fieldPath string) int

GetFieldPathDepth gets the depth of field path

func GetNestedField

func GetNestedField(data interface{}, fieldPath string) (interface{}, bool)

GetNestedField gets field value from nested map or struct Supports complex operations like dot-separated field paths, array indices, Map keys Supported formats: - "device.info.name" (nested fields) - "data[0]" (array index) - "users[0].name" (field of array element) - "config['key']" (string key) - "items[0][1]" (multi-dimensional array) - "nested.data[0].field['key']" (mixed access)

func IsNestedField

func IsNestedField(fieldName string) bool

IsNestedField checks if field name contains dots or array indices (nested field)

func NormalizeFieldPath

func NormalizeFieldPath(fieldPath string) string

NormalizeFieldPath normalizes field path format

func SetNestedField

func SetNestedField(data map[string]interface{}, fieldPath string, value interface{}) error

SetNestedField sets field value in nested map, supports complex paths Automatically creates missing levels in the path

func ValidateFieldPath

func ValidateFieldPath(fieldPath string) error

ValidateFieldPath validates if field path format is correct

Types

type FieldAccessError

type FieldAccessError struct {
	Path    string
	Message string
}

FieldAccessError field access error

func (*FieldAccessError) Error

func (e *FieldAccessError) Error() string

type FieldAccessor

type FieldAccessor struct {
	Parts []FieldPart
}

FieldAccessor field accessor structure for parsing complex field paths

func ParseFieldPath

func ParseFieldPath(fieldPath string) (*FieldAccessor, error)

ParseFieldPath parses field path, supports complex access like dot notation, array index, Map keys Supported formats: - a.b.c (nested fields) - a.b[0] (array index) - a.b[0].c (field of array element) - a.b["key"] (string key) - a.b['key'] (string key) - a.b[123] (number key or array index) - a[0].b[1].c["key"] (mixed access)

type FieldPart

type FieldPart struct {
	Type    string // "field", "array_index", "map_key"
	Name    string // Field name or key name
	Index   int    // Array index (when Type is "array_index")
	Key     string // Map key (when Type is "map_key")
	KeyType string // Key type: "string", "number"
}

FieldPart represents a single part of field path

Jump to

Keyboard shortcuts

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