Documentation
¶
Overview ¶
Package keypath provides utilities for parsing and working with dot-notation key paths. Key paths are used to specify nested fields in configuration objects, supporting managed_keys filtering and path-aware configuration updates.
Index ¶
- func CollectMatchingPaths(data map[string]interface{}, kp KeyPath) [][]string
- func CompareValuesAtPath(a, b map[string]interface{}, path string) bool
- func DeleteValueAtPath(data map[string]interface{}, path []string) bool
- func ExpandWildcardPath(data map[string]interface{}, pattern string) []string
- func FilterMapByManagedKeys(data map[string]interface{}, managedKeys []string) map[string]interface{}
- func GetValueAtPath(data map[string]interface{}, path []string) (interface{}, bool)
- func IsKeyManaged(key string, managedKeys []string) bool
- func SetValueAtPath(data map[string]interface{}, path []string, value interface{})
- func Validate(key string) error
- type KeyPath
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectMatchingPaths ¶
CollectMatchingPaths finds all paths in a data map that match the given key path. Wildcards are expanded to all matching keys at that level.
func CompareValuesAtPath ¶
CompareValuesAtPath compares values at a specific path in two maps. Returns true if values differ, false if they are equal.
func DeleteValueAtPath ¶
DeleteValueAtPath removes a value from a nested map at the given path. Returns true if the value was deleted, false if it didn't exist.
func ExpandWildcardPath ¶
ExpandWildcardPath expands a wildcard path against actual data. Returns all concrete paths that match the pattern.
func FilterMapByManagedKeys ¶
func FilterMapByManagedKeys(data map[string]interface{}, managedKeys []string) map[string]interface{}
FilterMapByManagedKeys filters a configuration map to only include managed keys. Returns a new map containing only the fields specified in managedKeys. Supports dot-notation paths and wildcards.
func GetValueAtPath ¶
GetValueAtPath retrieves a value from a nested map using the path segments. Returns the value and true if found, nil and false otherwise.
func IsKeyManaged ¶
IsKeyManaged checks if a specific key path is covered by the managed keys list. A key is managed if:
- It appears directly in the managed keys list
- A parent path appears in the managed keys list (implicit inclusion)
- It matches a wildcard pattern in the managed keys list
func SetValueAtPath ¶
SetValueAtPath sets a value in a nested map at the given path. Creates intermediate maps as needed.
Types ¶
type KeyPath ¶
type KeyPath struct {
Segments []string // Individual path segments
HasWildcard bool // True if path contains a wildcard (*)
WildcardIdx int // Index of wildcard segment (-1 if none)
Original string // Original unparsed path string
}
KeyPath represents a parsed dot-notation key path.
func Parse ¶
Parse parses a dot-notation key string into a KeyPath. Examples:
- "name" -> single segment
- "radio_config.band_24" -> two segments
- "port_config.*.vlan_id" -> three segments with wildcard
func (KeyPath) Matches ¶
Matches returns true if this path matches the given pattern. Wildcards (*) in the pattern match any single segment.
func (KeyPath) StartsWith ¶
StartsWith returns true if this path starts with the given prefix path.