Documentation
¶
Overview ¶
Package dictutil provides utility functions for working with nested map[string]any configuration dictionaries.
Index ¶
- func DeepMerge(base, overlay map[string]any) map[string]any
- func FlatKeys(data map[string]any) []string
- func FlatKeysWithPrefix(data map[string]any, prefix string) []string
- func Flatten(data map[string]any) map[string]any
- func GetNested(data map[string]any, keyPath string) (any, bool)
- func HasNested(data map[string]any, keyPath string) bool
- func SetNested(data map[string]any, keyPath string, value any) error
- func ShallowMerge(base, overlay map[string]any) map[string]any
- func Unflatten(data map[string]any) map[string]any
- type PathError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepMerge ¶
DeepMerge recursively merges overlay into base. For any key present in both:
- If both values are maps, recurse.
- Otherwise, the overlay value replaces the base value.
Returns a new map; neither base nor overlay is modified.
func FlatKeysWithPrefix ¶
FlatKeysWithPrefix returns flat keys that start with the given prefix, with the prefix stripped from each key.
func Flatten ¶
Flatten converts a nested map into a flat map with dot-separated keys. Only leaf values (non-map values) are included.
Example: {"database": {"host": "localhost"}} → {"database.host": "localhost"}
func GetNested ¶
GetNested retrieves a value from a nested map using a dot-separated key path. Returns (value, true) if found, (nil, false) otherwise.
func SetNested ¶
SetNested sets a value in a nested map using a dot-separated key path. Intermediate maps are created as needed. Returns an error if an intermediate value exists but is not a map.
func ShallowMerge ¶
ShallowMerge copies base then applies overlay at the top level only.