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

Method UnpackUntilKind

model/value.go:254–266  ·  view source on GitHub ↗

UnpackUntilKind unpacks the reflect value until it matches the given kind.

(k reflect.Kind)

Source from the content-addressed store, hash-verified

252
253// UnpackUntilKind unpacks the reflect value until it matches the given kind.
254func (v *Value) UnpackUntilKind(k reflect.Kind) (*Value, error) {
255 res := v.value
256 for {
257 if res.Kind() == k {
258 return NewValue(res), nil
259 }
260 if res.Kind() == reflect.Interface || res.Kind() == reflect.Pointer && !res.IsNil() {
261 res = res.Elem()
262 continue
263 }
264 return nil, fmt.Errorf("could not unpack to kind: %s", k)
265 }
266}
267
268// UnpackUntilKinds unpacks the reflect value until it matches the given kind.
269func (v *Value) UnpackUntilKinds(kinds ...reflect.Kind) (*Value, error) {

Callers 4

SetMapKeyMethod · 0.95
GetMapKeyMethod · 0.95
DeleteMapKeyMethod · 0.95
MapKeysMethod · 0.95

Calls 2

NewValueFunction · 0.85
KindMethod · 0.80

Tested by

no test coverage detected