buildTableConfig builds a TableConfig from a slice of structs
(val reflect.Value, title string)
| 238 | |
| 239 | // buildTableConfig builds a TableConfig from a slice of structs |
| 240 | func buildTableConfig(val reflect.Value, title string) TableConfig { |
| 241 | renderLog.Printf("Building table config: title=%s, elements=%d", title, val.Len()) |
| 242 | |
| 243 | config := TableConfig{ |
| 244 | Title: "", |
| 245 | } |
| 246 | |
| 247 | if val.Len() == 0 { |
| 248 | return config |
| 249 | } |
| 250 | |
| 251 | // Get the element type |
| 252 | elemType := val.Type().Elem() |
| 253 | for elemType.Kind() == reflect.Pointer { |
| 254 | elemType = elemType.Elem() |
| 255 | } |
| 256 | |
| 257 | // Build headers from struct fields |
| 258 | headers, fieldPaths, fieldTags := buildTableHeaders(elemType) |
| 259 | config.Headers = headers |
| 260 | |
| 261 | // Build rows |
| 262 | config.Rows = buildTableRows(val, fieldPaths, fieldTags) |
| 263 | |
| 264 | return config |
| 265 | } |
| 266 | |
| 267 | // buildTableHeaders extracts column headers, field index paths, and tags from a struct type, |
| 268 | // flattening anonymous embedded struct fields into the top-level column list. |