keypath

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectMatchingPaths

func CollectMatchingPaths(data map[string]interface{}, kp KeyPath) [][]string

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

func CompareValuesAtPath(a, b map[string]interface{}, path string) bool

CompareValuesAtPath compares values at a specific path in two maps. Returns true if values differ, false if they are equal.

func DeleteValueAtPath

func DeleteValueAtPath(data map[string]interface{}, path []string) bool

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

func ExpandWildcardPath(data map[string]interface{}, pattern string) []string

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

func GetValueAtPath(data map[string]interface{}, path []string) (interface{}, bool)

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

func IsKeyManaged(key string, managedKeys []string) bool

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

func SetValueAtPath(data map[string]interface{}, path []string, value interface{})

SetValueAtPath sets a value in a nested map at the given path. Creates intermediate maps as needed.

func Validate

func Validate(key string) error

Validate checks if a key path string is valid. Returns an error if the path is malformed.

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

func Parse(key string) KeyPath

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) Depth

func (kp KeyPath) Depth() int

Depth returns the nesting depth of the key path.

func (KeyPath) First

func (kp KeyPath) First() string

First returns the first segment of the path.

func (KeyPath) IsNested

func (kp KeyPath) IsNested() bool

IsNested returns true if the path has more than one segment.

func (KeyPath) Matches

func (kp KeyPath) Matches(pattern KeyPath) bool

Matches returns true if this path matches the given pattern. Wildcards (*) in the pattern match any single segment.

func (KeyPath) Rest

func (kp KeyPath) Rest() KeyPath

Rest returns a new KeyPath with all segments except the first.

func (KeyPath) StartsWith

func (kp KeyPath) StartsWith(prefix KeyPath) bool

StartsWith returns true if this path starts with the given prefix path.

func (KeyPath) String

func (kp KeyPath) String() string

String returns the dot-notation string representation.

Jump to

Keyboard shortcuts

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