DeleteMapKey deletes the key from the map.
(key string)
| 135 | |
| 136 | // DeleteMapKey deletes the key from the map. |
| 137 | func (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. |
| 162 | func (v *Value) MapKeys() ([]string, error) { |