MCPcopy Create free account
hub / github.com/github/gh-aw / collectTableFields

Function collectTableFields

pkg/console/render.go:284–317  ·  view source on GitHub ↗

collectTableFields recursively walks a struct type, inlining the fields of any anonymous embedded structs so they appear as top-level table columns.

(t reflect.Type, prefix []int)

Source from the content-addressed store, hash-verified

282// collectTableFields recursively walks a struct type, inlining the fields of any
283// anonymous embedded structs so they appear as top-level table columns.
284func collectTableFields(t reflect.Type, prefix []int) []tableField {
285 fields := make([]tableField, 0, t.NumField())
286 for i := range t.NumField() {
287 field := t.Field(i)
288 fieldPath := make([]int, len(prefix)+1)
289 copy(fieldPath, prefix)
290 fieldPath[len(prefix)] = i
291
292 if field.Anonymous {
293 if embeddedType, ok := embeddedStructType(field.Type); ok {
294 fields = append(fields, collectTableFields(embeddedType, fieldPath)...)
295 continue
296 }
297 }
298
299 tag := parseConsoleTag(field.Tag.Get("console"))
300
301 if tag.skip {
302 continue
303 }
304
305 headerName := field.Name
306 if tag.header != "" {
307 headerName = tag.header
308 }
309
310 fields = append(fields, tableField{
311 header: headerName,
312 path: fieldPath,
313 tag: tag,
314 })
315 }
316 return fields
317}
318
319// buildTableRows builds the row data for a slice of struct elements.
320func buildTableRows(val reflect.Value, fieldPaths [][]int, fieldTags []consoleTag) [][]string {

Callers 1

buildTableHeadersFunction · 0.85

Calls 3

embeddedStructTypeFunction · 0.85
parseConsoleTagFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected