Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Tabulate ¶
Tabulate creates a string table from supplied rows. Columns are created in sorted ascending if all columns are not provided.
func WithStrict ¶
func WithStrict(v bool) option
WithStrict sets strict in options. In strict mode colums need to be defined before [Add] call.
Types ¶
type Tabulator ¶
type Tabulator struct {
// contains filtered or unexported fields
}
func (*Tabulator) Add ¶
Add supports adding values without re-defining the column names. In non-strict mode: If amount of values is larger than the defined columns, Add creates ad-hoc dynamic column names. In strict mode: Add will panic if amount of values is larger than defined columns.
Example ¶
data := []struct { time time.Time metric string count any }{ { time: time.Time{}, metric: "a", count: 1, }, { time: time.Time{}, metric: "b", count: 20, }, { time: time.Time{}, metric: "c", count: 1.23, }, } tab := New([]string{"time", "metric", "count"}) for _, elem := range data { tab.Add(func() string { return elem.time.Format("2006-01-02T15:04") }, elem.metric, elem.count) } tab.Print(os.Stdout)
Output: | time | metric | count | |------------------|--------|-------| | 0001-01-01T00:00 | a | 1 | | 0001-01-01T00:00 | b | 20 | | 0001-01-01T00:00 | c | 1.23 |
Click to show internal directories.
Click to hide internal directories.