This section describes the gotable APIs.
func Create(columns ...string) (*table.Table, error)
func CreateByStruct(v interface{}) (*table.Table, error)
func CreateSafeTable(columns ...string) (*table.SafeTable, error)
func Version() string
func Versions() []string
The gotable.Default
constant replaces the default value stored in column. Refer to Set Default Values in the Demo
section for more information.
gotable.Default
Currently,csv and json file are supported.
func Read(path string) (*table.Table, error)
The following constants are used in conjunction with the *table.SetColumnColor
method to change the column color.
Default display
gotable.TerminalDefault
Fonts are highlighted
gotable.Highlight
Underline
gotable.Underline
Font flash
gotable.Flash
gotable.Black
gotable.Red
gotable.Green
gotable.Yellow
gotable.Blue
gotable.Purple
gotable.Cyan
gotable.Write
Do not set the background color
gotable.NoneBackground
The clear method is used to clear all data in the table, include columns and rows.
func (tb *Table) Clear()
The type method returns a type of table.
func (tb *Table) Type() string
Add a row to the table. Support Map and Slice. See the Demo section for more information.
func (tb *Table) AddRow(row interface{}) error
Method AddRows
add a list of rows. It returns a slice that consists of adding failed rows.
func (tb *Table) AddRows(rows []map[string]string) []map[string]string
func (tb *Table) AddColumn(column string) error
*Table
implements fmt.Stringer
interface, so you can use the fmt.Print
, fmt.Printf
functions
and so on to print the contents of the table instance.
func (tb *Table) String() string
By default, the default value for all columns is an empty string.
func (b *base) SetDefault(column string, defaultValue string)
func (b *base) DropDefault(column string)
Use table method GetDefault
to get default value of column. If column does not exist in the table, the method returns an empty string.
func (b *base) GetDefault(column string) string
Use table method GetDefaults
to get default map of head.
func (b *base) GetDefaults() map[string]string
By default, the table is centered. You can set a header to be left aligned or right aligned. See the next section for more details on how to use it.
func (tb *Table) Align(column string, mode int)
Use table method Empty
to check if the table is empty.
func (tb *Table) Empty() bool
Use table method GetColumns
to get a list of columns.
func (b *base) GetColumns() []string
Use table method GetValues
to get the map that save values.
func (tb *Table) GetValues() []map[string]string
func (tb *Table) Exist(value map[string]string) bool
func (tb *Table) Length() int
Use table method JSON
to convert the table to JSON format.
The argument indent
indicates the number of indents.
If the argument indent
is less than or equal to 0, then the JSON
method unindents.
func (tb *Table) JSON(indent int) (string, error)
Use table method XML
to convert the table to XML format.
The argument indent
indicates the number of indents.
If the argument indent
is less than or equal to 0, then the XML
method unindents.
func (tb *Table) XML(indent int) string
Use table method ToJsonFile
to save the table data to a JSON file.
func (tb *Table) ToJsonFile(path string, indent int) error
Use table method ToCSVFile
to save the table data to a CSV file.
func (tb *Table) ToCSVFile(path string) error
Use table method CloseBorder
to close table border.
func (tb *Table) CloseBorder()
Use table method OpenBorder
to open table border. By default, the border property is turned on.
func (tb *Table) OpenBorder()
Table method HasColumn
determine whether the column is included.
func (tb *Table) HasColumn(column string) bool
Table method EqualColumns
is used to check whether the columns of two tables are the same. This method returns
true if the columns of the two tables are identical (length, name, order, alignment, default), and false otherwise.
func (tb *Table) EqualColumns(other *Table) bool
Table method SetColumnColor
is used to set the color of a specific column. The first parameter specifies the name
of the column to be modified. The second parameter indicates the type of font to display. Refer to the Color control
section in this document for more information. The third and fourth parameters specify the font and background color.
func (tb *Table) SetColumnColor(columnName string, display, fount, background int)
By default, a new blank line will print after table printing. You can designate your ending string by reset
table.End
.
Method IsSimpleTable is used to check whether the table type is simple table.
func (b *base) IsSimpleTable() bool
Method IsSafeTable is used to check whether the table type is safe table.
func(b *base) IsSafeTable() bool
The type method returns a type of table.
func (tb *Table) Type() string
Method IsSimpleTable is used to check whether the table type is simple table.
func (b *base) IsSimpleTable() bool
Method IsSafeTable is used to check whether the table type is safe table.
func(b *base) IsSafeTable() bool
Add a row to the safe table. Only support Map. See the Demo section for more information.
func (s *SafeTable) AddRow(row interface{}) error
Method AddRows
add a list of rows. It returns a slice that consists of adding failed rows.
func (s *SafeTable) AddRows(rows []map[string]string) []map[string]string
By default, a new blank line will print after table printing. You can designate your ending string by reset
table.End
.
func (s *SafeTable) AddColumn(column string) error
By default, the default value for all columns is an empty string.
func (b *base) SetDefault(column string, defaultValue string)
func (b *base) DropDefault(column string)
Use table method GetDefaults
to get default map of head.
func (b *base) GetDefaults() map[string]string
func (s *SafeTable) Length() int
*SafeTable
implements fmt.Stringer
interface, so you can use the fmt.Print
, fmt.Printf
functions
and so on to print the contents of the table instance.
func (st *SafeTable) String() string
Use table method GetColumns
to get a list of columns.
func (b *base) GetColumns() []string