How to Display Tables in a Go CLI

Cli
Use the tablewriter library to format and display tabular data in a Go CLI application.

Go has no built-in table formatter for CLI output, so you must use a third-party library like github.com/olekukonko/tablewriter to render tabular data. Install the library and pass your data slice to NewWriter to generate the formatted table.

import "github.com/olekukonko/tablewriter"

data := [][]string{
	{"Name", "Age"},
	{"Alice", "30"},
	{"Bob", "25"},
}
table := tablewriter.NewWriter(os.Stdout)
table.AppendBulk(data)
table.Render()