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

Method SetMapKey

model/value_map.go:41–60  ·  view source on GitHub ↗

SetMapKey sets the value at the specified key in the map.

(key string, value *Value)

Source from the content-addressed store, hash-verified

39
40// SetMapKey sets the value at the specified key in the map.
41func (v *Value) SetMapKey(key string, value *Value) error {
42 switch {
43 case v.isDencodingMap():
44 m, err := v.dencodingMapValue()
45 if err != nil {
46 return fmt.Errorf("error getting map: %w", err)
47 }
48 m.Set(key, value)
49 return nil
50 case v.isStandardMap():
51 unpacked, err := v.UnpackUntilKind(reflect.Map)
52 if err != nil {
53 return fmt.Errorf("error unpacking value: %w", err)
54 }
55 unpacked.value.SetMapIndex(reflect.ValueOf(key), value.value)
56 return nil
57 default:
58 return fmt.Errorf("value is not a map")
59 }
60}
61
62func (v *Value) MapCopy() (*Value, error) {
63 res := NewMapValue()

Callers 15

TestMapCopyFunction · 0.95
TestValue_CopyFunction · 0.95
TestMapFunction · 0.80
MapCopyMethod · 0.80
TestValue_SetFunction · 0.80
TestValue_EqualTypeValueFunction · 0.80
TestValue_GoValueFunction · 0.80
nodesToValueFunction · 0.80
nodeToValueFunction · 0.80
TestWriter_SimpleScalarsFunction · 0.80
TestWriter_BoolAndNullFunction · 0.80

Calls 5

isDencodingMapMethod · 0.95
dencodingMapValueMethod · 0.95
isStandardMapMethod · 0.95
UnpackUntilKindMethod · 0.95
SetMethod · 0.45

Tested by 15

TestMapCopyFunction · 0.76
TestValue_CopyFunction · 0.76
TestMapFunction · 0.64
TestValue_SetFunction · 0.64
TestValue_EqualTypeValueFunction · 0.64
TestValue_GoValueFunction · 0.64
TestWriter_SimpleScalarsFunction · 0.64
TestWriter_BoolAndNullFunction · 0.64
TestWriter_SliceFunction · 0.64
TestWriter_NestedMapFunction · 0.64
TestWriter_CompactModeFunction · 0.64