(root any, jsonPath string)
| 267 | } |
| 268 | |
| 269 | func resolveJSONField(root any, jsonPath string) (reflect.Value, reflect.Value, string, error) { |
| 270 | current := reflect.ValueOf(root) |
| 271 | if current.Kind() != reflect.Pointer || current.IsNil() { |
| 272 | return reflect.Value{}, reflect.Value{}, "", errNonNilPointerRequired |
| 273 | } |
| 274 | |
| 275 | parts := strings.Split(jsonPath, ".") |
| 276 | for i, part := range parts { |
| 277 | structValue, err := ensureStructValue(current, part) |
| 278 | if err != nil { |
| 279 | return reflect.Value{}, reflect.Value{}, "", err |
| 280 | } |
| 281 | |
| 282 | fieldValue, fieldName, ok := findJSONField(structValue, part) |
| 283 | if !ok { |
| 284 | return reflect.Value{}, reflect.Value{}, "", fmt.Errorf("%w %q", errUnknownField, part) |
| 285 | } |
| 286 | |
| 287 | if i == len(parts)-1 { |
| 288 | return structValue, fieldValue, fieldName, nil |
| 289 | } |
| 290 | |
| 291 | next, err := nextStructPointer(fieldValue, part) |
| 292 | if err != nil { |
| 293 | return reflect.Value{}, reflect.Value{}, "", err |
| 294 | } |
| 295 | current = next |
| 296 | } |
| 297 | |
| 298 | return reflect.Value{}, reflect.Value{}, "", errEmptyFormatField |
| 299 | } |
| 300 | |
| 301 | func ensureStructValue(value reflect.Value, label string) (reflect.Value, error) { |
| 302 | if value.Kind() == reflect.Pointer { |
no test coverage detected