SetMapKey sets the value at the specified key in the map.
(key string, value *Value)
| 39 | |
| 40 | // SetMapKey sets the value at the specified key in the map. |
| 41 | func (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 | |
| 62 | func (v *Value) MapCopy() (*Value, error) { |
| 63 | res := NewMapValue() |