table

package
v0.0.0-...-96aface Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 9 Imported by: 0

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

View Source
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

type SafeTable struct {
	Row []sync.Map
	// contains filtered or unexported fields
}

func CreateSafeTable

func CreateSafeTable(set *Set) *SafeTable

CreateSafeTable returns a pointer of SafeTable.

func (*SafeTable) AddColumn

func (st *SafeTable) AddColumn(column string) error

AddColumn method used to add a new column for table. It returns an error when column has been existed.

func (*SafeTable) AddRow

func (st *SafeTable) AddRow(row interface{}) error

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

func (st *SafeTable) AddRows(rows []map[string]string) []map[string]string

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) Empty

func (st *SafeTable) Empty() bool

Empty method is used to determine whether the table is empty.

func (SafeTable) GetColumns

func (b SafeTable) GetColumns() []string

GetColumns method return a list of string that contains all column names.

func (SafeTable) GetDefault

func (b SafeTable) GetDefault(column string) string

GetDefault method returns default value with a designated column name.

func (SafeTable) GetDefaults

func (b SafeTable) GetDefaults() map[string]string

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) Length

func (st *SafeTable) Length() int

Length method returns an integer indicates the length of the table row.

func (SafeTable) SetDefault

func (b SafeTable) SetDefault(column string, defaultValue string)

SetDefault method used to set default value for a given column name.

func (*SafeTable) String

func (st *SafeTable) String() string

String method used to implement fmt.Stringer.

func (SafeTable) Type

func (b SafeTable) Type() string

Type method returns a table type string.

type Set

type Set struct {
	// contains filtered or unexported fields
}

func CreateSetFromString

func CreateSetFromString(columns ...string) (*Set, error)

func (*Set) Add

func (set *Set) Add(element string) error

func (*Set) Cap

func (set *Set) Cap() int

func (*Set) Clear

func (set *Set) Clear()

func (*Set) Equal

func (set *Set) Equal(other *Set) bool

func (*Set) Exist

func (set *Set) Exist(element string) bool

func (*Set) Get

func (set *Set) Get(name string) *cell.Column

func (*Set) Len

func (set *Set) Len() int

func (*Set) Remove

func (set *Set) Remove(element string) error

type Table

type Table struct {
	Row []map[string]cell.Cell
	// contains filtered or unexported fields
}

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

func CreateTable(set *Set) *Table

CreateTable function returns a pointer of Table.

func (*Table) AddColumn

func (tb *Table) AddColumn(column string) error

AddColumn method used to add a new column for table. It returns an error when column has been existed.

func (*Table) AddRow

func (tb *Table) AddRow(row interface{}) error

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

func (tb *Table) AddRows(rows []map[string]string) []map[string]string

AddRows used to add a slice of rows maps. It returns a slice of map which add failed.

func (*Table) Align

func (tb *Table) Align(column string, mode int)

func (*Table) Clear

func (tb *Table) Clear()

Clear the table. The table is cleared of all data.

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) Empty

func (tb *Table) Empty() bool

Empty method is used to determine whether the table is empty.

func (*Table) EqualColumns

func (tb *Table) EqualColumns(other *Table) bool

func (*Table) Exist

func (tb *Table) Exist(value map[string]string) bool

func (Table) GetColumns

func (b Table) GetColumns() []string

GetColumns method return a list of string that contains all column names.

func (Table) GetDefault

func (b Table) GetDefault(column string) string

GetDefault method returns default value with a designated column name.

func (Table) GetDefaults

func (b Table) GetDefaults() map[string]string

GetDefaults method return a map that contains all default value of each column. * map[column name] = default value

func (*Table) GetValues

func (tb *Table) GetValues() []map[string]string

func (*Table) GoString

func (tb *Table) GoString() string

GoString method used to implement fmt.GoStringer.

func (*Table) HasColumn

func (tb *Table) HasColumn(column string) bool

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

func (tb *Table) JSON(indent int) (string, error)

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) Length

func (tb *Table) Length() int

Length method returns an integer indicates the length of the table row.

func (*Table) OpenBorder

func (tb *Table) OpenBorder()

func (*Table) SetColumnColor

func (tb *Table) SetColumnColor(columnName string, display, fount, background int)

func (Table) SetDefault

func (b Table) SetDefault(column string, defaultValue string)

SetDefault method used to set default value for a given column name.

func (*Table) String

func (tb *Table) String() string

String method used to implement fmt.Stringer.

func (*Table) ToCSVFile

func (tb *Table) ToCSVFile(path string) error

func (*Table) ToJsonFile

func (tb *Table) ToJsonFile(path string, indent int) error

func (Table) Type

func (b Table) Type() string

Type method returns a table type string.

func (*Table) XML

func (tb *Table) XML(indent int) string

The XML method returns the XML format string corresponding to the gotable. The indent argument represents the indent value. If index is less than zero, the XML method treats it as zero.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL