Documentation ¶
Overview ¶
Package table define all table types methods. base.go contains basic methods of table types.
Package table define all table types methods. kind.go used to define table types.
Package table define all table types methods. print.go used to control table printing.
Index ¶
- Constants
- type SafeTable
- func (st *SafeTable) AddColumn(column string) error
- func (st *SafeTable) AddRow(row interface{}) error
- func (st *SafeTable) AddRows(rows []map[string]string) []map[string]string
- func (st *SafeTable) Clear()
- func (b SafeTable) DropDefault(column string)
- func (st *SafeTable) Empty() bool
- func (b SafeTable) GetColumns() []string
- func (b SafeTable) GetDefault(column string) string
- func (b SafeTable) GetDefaults() map[string]string
- func (b SafeTable) IsSafeTable() bool
- func (b SafeTable) IsSimpleTable() bool
- func (st *SafeTable) Length() int
- func (b SafeTable) SetDefault(column string, defaultValue string)
- func (st *SafeTable) String() string
- func (b SafeTable) Type() string
- type Set
- type Table
- func (tb *Table) AddColumn(column string) error
- func (tb *Table) AddRow(row interface{}) error
- func (tb *Table) AddRows(rows []map[string]string) []map[string]string
- func (tb *Table) Align(column string, mode int)
- func (tb *Table) Clear()
- func (tb *Table) CloseBorder()
- func (b Table) DropDefault(column string)
- func (tb *Table) Empty() bool
- func (tb *Table) EqualColumns(other *Table) bool
- func (tb *Table) Exist(value map[string]string) bool
- func (b Table) GetColumns() []string
- func (b Table) GetDefault(column string) string
- func (b Table) GetDefaults() map[string]string
- func (tb *Table) GetValues() []map[string]string
- func (tb *Table) GoString() string
- func (tb *Table) HasColumn(column string) bool
- func (b Table) IsSafeTable() bool
- func (b Table) IsSimpleTable() bool
- func (tb *Table) JSON(indent int) (string, error)
- func (tb *Table) Length() int
- func (tb *Table) OpenBorder()
- func (tb *Table) SetColumnColor(columnName string, display, fount, background int)
- func (b Table) SetDefault(column string, defaultValue string)
- func (tb *Table) String() string
- func (tb *Table) ToCSVFile(path string) error
- func (tb *Table) ToJsonFile(path string, indent int) error
- func (b Table) Type() string
- func (tb *Table) XML(indent int) string
Constants ¶
const ( C = cell.AlignCenter L = cell.AlignLeft R = cell.AlignRight Default = "__DEFAULT__" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SafeTable ¶
func CreateSafeTable ¶
CreateSafeTable returns a pointer of SafeTable.
func (*SafeTable) AddColumn ¶
AddColumn method used to add a new column for table. It returns an error when column has been existed.
func (*SafeTable) AddRow ¶
AddRow method support Map and Slice argument. For Map argument, you must put the data from each row into a Map and use column-data as key-value pairs. If the Map
does not contain a column, the table sets it to the default value. If the Map contains a column that does not exist, the AddRow method returns an error.
For Slice argument, you must ensure that the slice length is equal to the column length. Method will automatically
map values in Slice and columns. The default value cannot be omitted and must use gotable.Default constant.
Return error types:
- *exception.UnsupportedRowTypeError: It returned when the type of the argument is not supported.
- *exception.RowLengthNotEqualColumnsError: It returned if the argument is type of the Slice but the length is different from the length of column.
- *exception.ColumnDoNotExistError: It returned if the argument is type of the Map but contains a nonexistent column as a key.
func (*SafeTable) AddRows ¶
AddRows used to add a slice of rows map. It returns a slice of map which add failed.
func (*SafeTable) Clear ¶
func (st *SafeTable) Clear()
Clear the table. The table is cleared of all data.
func (SafeTable) DropDefault ¶
func (b SafeTable) DropDefault(column string)
DropDefault method used to delete default value for designated column.
func (SafeTable) GetColumns ¶
func (b SafeTable) GetColumns() []string
GetColumns method return a list of string that contains all column names.
func (SafeTable) GetDefault ¶
GetDefault method returns default value with a designated column name.
func (SafeTable) GetDefaults ¶
GetDefaults method return a map that contains all default value of each column. * map[column name] = default value
func (SafeTable) IsSafeTable ¶
func (b SafeTable) IsSafeTable() bool
IsSafeTable method returns a bool value indicate the table type is safeTableType.
func (SafeTable) IsSimpleTable ¶
func (b SafeTable) IsSimpleTable() bool
IsSimpleTable method returns a bool value indicate the table type is simpleTableType.
func (SafeTable) SetDefault ¶
SetDefault method used to set default value for a given column name.
type Table ¶
Table struct:
- Columns: Save the table columns.
- Row: Save the list of column and value mapping.
- border: A flag indicates whether to print table border. If the value is `true`, table will show its border. Default is true(By CreateTable function).
- tableType: Type of table.
func CreateTable ¶
CreateTable function returns a pointer of Table.
func (*Table) AddColumn ¶
AddColumn method used to add a new column for table. It returns an error when column has been existed.
func (*Table) AddRow ¶
AddRow method support Map and Slice argument. For Map argument, you must put the data from each row into a Map and use column-data as key-value pairs. If the Map
does not contain a column, the table sets it to the default value. If the Map contains a column that does not exist, the AddRow method returns an error.
For Slice argument, you must ensure that the slice length is equal to the column length. Method will automatically
map values in Slice and columns. The default value cannot be omitted and must use gotable.Default constant.
Return error types:
- *exception.UnsupportedRowTypeError: It returned when the type of the argument is not supported.
- *exception.RowLengthNotEqualColumnsError: It returned if the argument is type of the Slice but the length is different from the length of column.
- *exception.ColumnDoNotExistError: It returned if the argument is type of the Map but contains a nonexistent column as a key.
func (*Table) AddRows ¶
AddRows used to add a slice of rows maps. It returns a slice of map which add failed.
func (*Table) CloseBorder ¶
func (tb *Table) CloseBorder()
func (Table) DropDefault ¶
func (b Table) DropDefault(column string)
DropDefault method used to delete default value for designated column.
func (*Table) EqualColumns ¶
func (Table) GetColumns ¶
func (b Table) GetColumns() []string
GetColumns method return a list of string that contains all column names.
func (Table) GetDefault ¶
GetDefault method returns default value with a designated column name.
func (Table) GetDefaults ¶
GetDefaults method return a map that contains all default value of each column. * map[column name] = default value
func (Table) IsSafeTable ¶
func (b Table) IsSafeTable() bool
IsSafeTable method returns a bool value indicate the table type is safeTableType.
func (Table) IsSimpleTable ¶
func (b Table) IsSimpleTable() bool
IsSimpleTable method returns a bool value indicate the table type is simpleTableType.
func (*Table) JSON ¶
The JSON method returns the JSON string corresponding to the gotable. The indent argument represents the indent value. If index is less than zero, the JSON method treats it as zero.
func (*Table) OpenBorder ¶
func (tb *Table) OpenBorder()
func (*Table) SetColumnColor ¶
func (Table) SetDefault ¶
SetDefault method used to set default value for a given column name.