MCPcopy
hub / github.com/TomWright/dasel / MapKeys

Method MapKeys

model/value_map.go:162–187  ·  view source on GitHub ↗

MapKeys returns a list of keys in the map.

()

Source from the content-addressed store, hash-verified

160
161// MapKeys returns a list of keys in the map.
162func (v *Value) MapKeys() ([]string, error) {
163 switch {
164 case v.isDencodingMap():
165 m, err := v.dencodingMapValue()
166 if err != nil {
167 return nil, fmt.Errorf("error getting map: %w", err)
168 }
169 return m.Keys(), nil
170 case v.isStandardMap():
171 unpacked, err := v.UnpackUntilKind(reflect.Map)
172 if err != nil {
173 return nil, fmt.Errorf("error unpacking value: %w", err)
174 }
175 keys := unpacked.value.MapKeys()
176 strKeys := make([]string, len(keys))
177 for i, k := range keys {
178 strKeys[i] = k.String()
179 }
180 return strKeys, nil
181 default:
182 return nil, ErrUnexpectedType{
183 Expected: TypeMap,
184 Actual: v.Type(),
185 }
186 }
187}
188
189// RangeMap iterates over each key in the map and calls the provided function with the key and value.
190func (v *Value) RangeMap(f func(string, *Value) error) error {

Callers 7

EqualTypeValueMethod · 0.95
RangeMapMethod · 0.95
MapKeyValuesMethod · 0.95
MapLenMethod · 0.95
TestMapFunction · 0.80
WriteMethod · 0.80
func_keys.goFile · 0.80

Calls 7

isDencodingMapMethod · 0.95
dencodingMapValueMethod · 0.95
isStandardMapMethod · 0.95
UnpackUntilKindMethod · 0.95
TypeMethod · 0.95
KeysMethod · 0.80
StringMethod · 0.45

Tested by 1

TestMapFunction · 0.64