Quick Start
Define Your Data
Section titled “Define Your Data”go-output has three core data shapes: Table, Tree, and Graph. Define your data once, then render it in any format that supports that shape.
Tables
Section titled “Tables”import "github.com/larsartmann/go-output"
data := output.NewTable([]string{"Name", "Health", "Complexity"})data.AddRow([]string{"Alpha", "90%", "7/10"})data.AddRow([]string{"Beta", "75%", "5/10"})data.SetFooter([]string{"Total", "2", "-"})root := output.NewTreeNode("root", "Projects")root.AddChild(output.NewTreeNode("alpha", "Alpha"))root.AddChild(output.NewTreeNode("beta", "Beta"))Graphs
Section titled “Graphs”b := output.NewGraphBuilder()b.AddNode(output.NewGraphNode("a", "API Gateway"))b.AddNode(output.NewGraphNode("b", "Backend"))b.AddEdge(output.NewGraphEdge("a", "b"))g := b.Build()Render with CQRS Pure Functions
Section titled “Render with CQRS Pure Functions”The CQRS API (v0.30.0+) is the recommended way to render. Pure functions, no side effects:
import ( "github.com/larsartmann/go-output/graph" "github.com/larsartmann/go-output/tree" "github.com/larsartmann/go-output/delimited")
// Same Graph, multiple formatsdot, _ := graph.RenderDOT(g)mermaid, _ := graph.RenderMermaid(g)
// Tree to ASCIIascii, _ := tree.RenderASCII(root)
// Table to CSVcsv, _ := delimited.RenderCSV(data)Runtime Format Selection
Section titled “Runtime Format Selection”Use the Format enum for CLI flags and runtime dispatch:
format, err := output.ParseFormat("json")if err != nil { panic(err)}
fmt.Println(format.Supports(output.ShapeTable)) // truefmt.Println(format.Shapes()) // [table tree graph]fmt.Println(format.String()) // "json"
// Find all formats that support a given shapefor _, f := range output.FormatsForShape(output.ShapeGraph) { fmt.Println(f) // json, yaml, toml, d2, mermaid, dot, plantuml}Unified Dispatch
Section titled “Unified Dispatch”Dispatch through the unified renderer (requires importing the relevant sub-module):
out, err := output.RenderTable(data, output.FormatHTML, output.RenderOptions{ ColorMode: output.ColorModeAuto,})Cross-Shape Projections
Section titled “Cross-Shape Projections”Convert between data shapes as pure functions:
// Table -> Graph (auto-generates edges between consecutive rows)g := output.TableToGraph(data)
// Graph -> Tree (follows edges from root, cycle-guarded)t := output.GraphToTree(g)
// Graph -> Table (one row per node)tbl := output.GraphToTable(g)Next Steps
Section titled “Next Steps”- Learn about the CQRS architecture in depth
- Explore NOM real-time progress for workflow visualization
- Browse all 16 formats