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

Method DeleteMapKey

model/value_map.go:137–159  ·  view source on GitHub ↗

DeleteMapKey deletes the key from the map.

(key string)

Source from the content-addressed store, hash-verified

135
136// DeleteMapKey deletes the key from the map.
137func (v *Value) DeleteMapKey(key string) error {
138 switch {
139 case v.isDencodingMap():
140 m, err := v.dencodingMapValue()
141 if err != nil {
142 return fmt.Errorf("error getting map: %w", err)
143 }
144 m.Delete(key)
145 return nil
146 case v.isStandardMap():
147 unpacked, err := v.UnpackUntilKind(reflect.Map)
148 if err != nil {
149 return fmt.Errorf("error unpacking value: %w", err)
150 }
151 unpacked.value.SetMapIndex(reflect.ValueOf(key), reflect.Value{})
152 return nil
153 default:
154 return ErrUnexpectedType{
155 Expected: TypeMap,
156 Actual: v.Type(),
157 }
158 }
159}
160
161// MapKeys returns a list of keys in the map.
162func (v *Value) MapKeys() ([]string, error) {

Callers 1

TestMapFunction · 0.80

Calls 6

isDencodingMapMethod · 0.95
dencodingMapValueMethod · 0.95
isStandardMapMethod · 0.95
UnpackUntilKindMethod · 0.95
TypeMethod · 0.95
DeleteMethod · 0.45

Tested by 1

TestMapFunction · 0.64