buildTableRows builds the row data for a slice of struct elements.
(val reflect.Value, fieldPaths [][]int, fieldTags []consoleTag)
| 318 | |
| 319 | // buildTableRows builds the row data for a slice of struct elements. |
| 320 | func buildTableRows(val reflect.Value, fieldPaths [][]int, fieldTags []consoleTag) [][]string { |
| 321 | var rows [][]string |
| 322 | for i := range val.Len() { |
| 323 | elem := val.Index(i) |
| 324 | // Dereference pointer if needed |
| 325 | for elem.Kind() == reflect.Pointer { |
| 326 | if elem.IsNil() { |
| 327 | break |
| 328 | } |
| 329 | elem = elem.Elem() |
| 330 | } |
| 331 | |
| 332 | if elem.Kind() != reflect.Struct { |
| 333 | continue |
| 334 | } |
| 335 | |
| 336 | var row []string |
| 337 | for j, fieldPath := range fieldPaths { |
| 338 | field, ok := fieldByIndexSafe(elem, fieldPath) |
| 339 | if !ok { |
| 340 | row = append(row, "") |
| 341 | continue |
| 342 | } |
| 343 | row = append(row, formatFieldValueWithTag(field, fieldTags[j])) |
| 344 | } |
| 345 | rows = append(rows, row) |
| 346 | } |
| 347 | return rows |
| 348 | } |
| 349 | |
| 350 | func fieldByIndexSafe(val reflect.Value, path []int) (reflect.Value, bool) { |
| 351 | current := val |
no test coverage detected