Documentation
¶
Index ¶
- func MapLookup(mapToLookup map[string]interface{}, keys ...string) interface{}
- type ReadOnlyMap
- func (r *ReadOnlyMap[K, V]) Append(entries map[K]V) *ReadOnlyMap[K, V]
- func (r *ReadOnlyMap[K, V]) ForEach(fn func(K, V))
- func (r *ReadOnlyMap[K, V]) Get(key K) (V, bool)
- func (r *ReadOnlyMap[K, V]) Has(key K) bool
- func (r *ReadOnlyMap[K, V]) Keys() iter.Seq[K]
- func (r *ReadOnlyMap[K, V]) Len() int
- func (r *ReadOnlyMap[K, V]) Remove(entries []K) *ReadOnlyMap[K, V]
- func (r *ReadOnlyMap[K, V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapLookup ¶
MapLookup traverses a nested map[string]interface{} using a sequence of keys.
Given a root map and a variadic list of keys, MapLookup attempts to follow the path described by the keys through nested maps. If the full path exists, it returns the value found at the end of the path. If any key is missing or a value along the path is not a map[string]interface{}, it returns nil.
Example usage:
m := map[string]interface{}{
"a": map[string]interface{}{
"b": map[string]interface{}{
"c": 42,
},
},
}
v := MapLookup(m, "a", "b", "c") // v == 42
Parameters:
- mapToLookup: the root map to search
- keys: a variadic list of keys representing the path to traverse
Returns:
- The value at the end of the key path if found, or nil otherwise.
Types ¶
type ReadOnlyMap ¶ added in v0.68.0
type ReadOnlyMap[K comparable, V any] struct { // contains filtered or unexported fields }
ReadOnlyMap provides a read-only view of a map
func NewReadOnlyMap ¶ added in v0.68.0
func NewReadOnlyMap[K comparable, V any](data map[K]V) *ReadOnlyMap[K, V]
NewReadOnlyMap creates a new read-only map from an existing map The original map is copied to prevent external modifications
func (*ReadOnlyMap[K, V]) Append ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) Append(entries map[K]V) *ReadOnlyMap[K, V]
Append returns a new read-only map with the provided entries added
func (*ReadOnlyMap[K, V]) ForEach ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) ForEach(fn func(K, V))
ForEach iterates over all key-value pairs
func (*ReadOnlyMap[K, V]) Get ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) Get(key K) (V, bool)
Get retrieves a value by key
func (*ReadOnlyMap[K, V]) Has ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) Has(key K) bool
Has checks if a key exists
func (*ReadOnlyMap[K, V]) Keys ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) Keys() iter.Seq[K]
Keys returns all keys
func (*ReadOnlyMap[K, V]) Len ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) Len() int
Len returns the number of elements
func (*ReadOnlyMap[K, V]) Remove ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) Remove(entries []K) *ReadOnlyMap[K, V]
Remove returns a new read-only map with the provided keys removed
func (*ReadOnlyMap[K, V]) Values ¶ added in v0.68.0
func (r *ReadOnlyMap[K, V]) Values() iter.Seq[V]
Values returns all values