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

Function RenderStruct

pkg/console/render.go:29–35  ·  view source on GitHub ↗

RenderStruct renders a Go struct to console output using reflection and struct tags. It supports: - Rendering structs as markdown-style headers with key-value pairs - Rendering slices as tables using the console table renderer - Rendering maps as markdown headers Struct tags: - `console:"title:My T

(v any)

Source from the content-addressed store, hash-verified

27// - `console:"omitempty"` - Skips zero values
28// - `console:"-"` - Skips the field entirely
29func RenderStruct(v any) string {
30 renderLog.Printf("Rendering struct: type=%T", v)
31 var output strings.Builder
32 renderValue(reflect.ValueOf(v), "", &output, 0)
33 renderLog.Printf("Struct rendering complete: output_size=%d bytes", output.Len())
34 return output.String()
35}
36
37// renderValue recursively renders a reflect.Value to the output builder
38func renderValue(val reflect.Value, title string, output *strings.Builder, depth int) {

Calls 3

renderValueFunction · 0.85
PrintfMethod · 0.45
StringMethod · 0.45