table

package
v0.0.0-...-d2a41d4 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 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 {
	Rows [][]sync.Map
	// contains filtered or unexported fields
}

func CreateSafeTable

func CreateSafeTable(set *Set) *SafeTable

CreateSafeTable returns a pointer of SafeTable.

func (*SafeTable) AddColumn

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

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

func (*SafeTable) AddRow

func (s *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 (s *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 (s *SafeTable) Clear()

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

func (SafeTable) DropDefault

func (b SafeTable) DropDefault(partNumber int, column string)

DropDefault method used to delete default value for designated column.

func (*SafeTable) Empty

func (s *SafeTable) Empty() bool

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

func (SafeTable) GetDefault

func (b SafeTable) GetDefault(partNumber int, column string) string

GetDefault method returns default value with a designated column name.

func (SafeTable) GetDefaults

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

GetDefaults method return a map that contains all default value of each columns. * 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 (s *SafeTable) Length() int

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

func (SafeTable) SetDefault

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

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

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 {
	Rows [][]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) AdaptColLen

func (tb *Table) AdaptColLen(longPN int, shortPN int, adCol string) error

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

func (tb *Table) AddPNColumn(partNumber int, column string) error

func (*Table) AddPNRow

func (tb *Table) AddPNRow(partNumber int, row interface{}) error

func (*Table) AddPart

func (tb *Table) AddPart(columns ...string) error

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

func (tb *Table) DelPNRows(partNumber int) error

func (*Table) DelRows

func (tb *Table) DelRows() error

func (Table) DropDefault

func (b Table) DropDefault(partNumber int, 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 (tb *Table) GetColumns() []string

func (Table) GetDefault

func (b Table) GetDefault(partNumber int, column string) string

GetDefault method returns default value with a designated column name.

func (Table) GetDefaults

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

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

func (*Table) GetPNColumnLen

func (tb *Table) GetPNColumnLen(pn int, column string) (int, error)

func (*Table) GetPNColumns

func (tb *Table) GetPNColumns(partNumber int) []string

func (*Table) GetPNValues

func (tb *Table) GetPNValues(partNumber int) []map[string]string

func (*Table) GetValues

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

func (*Table) HasColumn

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

func (*Table) HasPNColumn

func (tb *Table) HasPNColumn(partNumber int, 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

func (*Table) OpenBorder

func (tb *Table) OpenBorder()

func (*Table) PNAlign

func (tb *Table) PNAlign(partNumber int, column string, mode int)

func (*Table) PNExist

func (tb *Table) PNExist(partNumber int, value map[string]string) bool

func (*Table) PartLength

func (tb *Table) PartLength() int

func (*Table) SetBorder

func (tb *Table) SetBorder(border int8)

func (*Table) SetColumnColor

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

func (*Table) SetColumnMaxLength

func (tb *Table) SetColumnMaxLength(partNumber int, column string, maxlength int) error

func (Table) SetDefault

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

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

func (*Table) SetPNTitleFill

func (tb *Table) SetPNTitleFill(partNumber int, fillpart int8) error

func (*Table) SetPNTitleHide

func (tb *Table) SetPNTitleHide(partNumber int, ishide bool) error

func (*Table) SetPNTitleLine

func (tb *Table) SetPNTitleLine(partNumber int, value int8) error

func (*Table) SetTitleHide

func (tb *Table) SetTitleHide(ishide bool) error

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