MCPcopy Create free account
hub / github.com/openclaw/gogcli / resolveJSONField

Function resolveJSONField

internal/sheetsformat/format.go:269–299  ·  view source on GitHub ↗
(root any, jsonPath string)

Source from the content-addressed store, hash-verified

267}
268
269func 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
301func ensureStructValue(value reflect.Value, label string) (reflect.Value, error) {
302 if value.Kind() == reflect.Pointer {

Callers 1

forceSendJSONFieldFunction · 0.85

Calls 4

ensureStructValueFunction · 0.85
findJSONFieldFunction · 0.85
nextStructPointerFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected