bndr/gotabulate 可以使用 Go 语言简单、美观的打印表格数据
文档
https://pkg.go.dev/github.com/bndr/gotabulate
https://github.com/bndr/gotabulate
安装
go get github.com/bndr/gotabulate
代码示例
package main
import (
"fmt"
"github.com/bndr/gotabulate"
)
func main() {
// Create Some Fake Rows
row_1 := []interface{}{"john", 20, "ready"}
row_2 := []interface{}{"bndr", 23, "ready"}
// Create an object from 2D interface array
t := gotabulate.Create([][]interface{}{row_1, row_2})
// Set the Headers (optional)
t.SetHeaders([]string{"name", "age", "status"})
// Set the Empty String (optional)
t.SetEmptyString("None")
// Set Align (Optional)
t.SetAlign("center")
// Print the result: grid, or simple
fmt.Println(t.Render("grid"))
}
输出
+---------+--------+-----------+
| name | age | status |
+=========+========+===========+
| john | 20 | ready |
+---------+--------+-----------+
| bndr | 23 | ready |
+---------+--------+-----------+