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

Function renderStruct

pkg/console/render.go:58–75  ·  view source on GitHub ↗

renderStruct renders a struct as markdown-style headers with key-value pairs

(val reflect.Value, title string, output *strings.Builder, depth int)

Source from the content-addressed store, hash-verified

56
57// renderStruct renders a struct as markdown-style headers with key-value pairs
58func renderStruct(val reflect.Value, title string, output *strings.Builder, depth int) {
59 typ := val.Type()
60 renderLog.Printf("Rendering struct: type=%s, title=%s, depth=%d, fields=%d", typ.Name(), title, depth, val.NumField())
61
62 // Print title without FormatInfoMessage styling
63 if title != "" {
64 if depth == 0 {
65 fmt.Fprintf(output, "# %s\n\n", title)
66 } else {
67 fmt.Fprintf(output, "%s %s\n\n", strings.Repeat("#", depth+1), title)
68 }
69 }
70
71 maxFieldLen := computeMaxFieldLen(val)
72 renderInlineEmbeddedFields(val, maxFieldLen, output, depth)
73
74 output.WriteString("\n")
75}
76
77// renderInlineEmbeddedFields renders the fields of an anonymous embedded struct
78// directly into the parent struct output, flattening the hierarchy.

Callers 1

renderValueFunction · 0.85

Calls 3

computeMaxFieldLenFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected