formatFieldValue formats a reflect.Value as a string for display
(val reflect.Value)
| 458 | |
| 459 | // formatFieldValue formats a reflect.Value as a string for display |
| 460 | func formatFieldValue(val reflect.Value) string { |
| 461 | // Dereference pointers |
| 462 | for val.Kind() == reflect.Pointer { |
| 463 | if val.IsNil() { |
| 464 | return "-" |
| 465 | } |
| 466 | val = val.Elem() |
| 467 | } |
| 468 | |
| 469 | if !val.IsValid() { |
| 470 | return "-" |
| 471 | } |
| 472 | |
| 473 | // Handle zero values |
| 474 | if isZeroValue(val) { |
| 475 | if val.Kind() == reflect.String { |
| 476 | return "-" |
| 477 | } |
| 478 | // For numeric types, return the actual value |
| 479 | if val.Kind() >= reflect.Int && val.Kind() <= reflect.Float64 { |
| 480 | if val.CanInterface() { |
| 481 | return fmt.Sprintf("%v", val.Interface()) |
| 482 | } |
| 483 | return formatNumericKind(val) |
| 484 | } |
| 485 | return "-" |
| 486 | } |
| 487 | |
| 488 | // Special handling for time.Time to avoid unexported field panic |
| 489 | if val.Type().String() == "time.Time" { |
| 490 | return formatTimeValue(val) |
| 491 | } |
| 492 | |
| 493 | // Only call Interface() if we can |
| 494 | if !val.CanInterface() { |
| 495 | return formatUnexportedValue(val) |
| 496 | } |
| 497 | |
| 498 | return fmt.Sprintf("%v", val.Interface()) |
| 499 | } |
| 500 | |
| 501 | // formatTimeValue formats a time.Time reflect value as a display string. |
| 502 | func formatTimeValue(val reflect.Value) string { |