MCPcopy
hub / github.com/kubernetes/client-go / findFieldInValue

Method findFieldInValue

util/jsonpath/jsonpath.go:305–336  ·  view source on GitHub ↗
(value *reflect.Value, node *FieldNode)

Source from the content-addressed store, hash-verified

303}
304
305func (j *JSONPath) findFieldInValue(value *reflect.Value, node *FieldNode) (reflect.Value, error) {
306 t := value.Type()
307 var inlineValue *reflect.Value
308 for ix := 0; ix < t.NumField(); ix++ {
309 f := t.Field(ix)
310 jsonTag := f.Tag.Get("json")
311 parts := strings.Split(jsonTag, ",")
312 if len(parts) == 0 {
313 continue
314 }
315 if parts[0] == node.Value {
316 return value.Field(ix), nil
317 }
318 if len(parts[0]) == 0 {
319 val := value.Field(ix)
320 inlineValue = &val
321 }
322 }
323 if inlineValue != nil {
324 if inlineValue.Kind() == reflect.Struct {
325 // handle 'inline'
326 match, err := j.findFieldInValue(inlineValue, node)
327 if err != nil {
328 return reflect.Value{}, err
329 }
330 if match.IsValid() {
331 return match, nil
332 }
333 }
334 }
335 return value.FieldByName(node.Value), nil
336}
337
338// evalField evaluates field of struct or key of map.
339func (j *JSONPath) evalField(input []reflect.Value, node *FieldNode) ([]reflect.Value, error) {

Callers 1

evalFieldMethod · 0.95

Calls 2

TypeMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected