table

package
v0.0.0-...-2caf503 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsFieldNotFoundError

func IsFieldNotFoundError(err error) bool

IsFieldNotFoundError asserts fieldNotFoundError.

func IsMultipleFieldsMatchingError

func IsMultipleFieldsMatchingError(err error) bool

IsMultipleFieldsMatchingError asserts multipleFieldsMatchingError.

func RemoveColors

func RemoveColors(s string) string

func SortMapSliceUsingColumnData

func SortMapSliceUsingColumnData(mapSlice []map[string]interface{}, byCol Column, fieldMapping map[string]string)

SortMapSliceUsingColumnData manages table-like sorting on non-table data types. This is especially useful if you want to encode in JSON the data in a table

Types

type Column

type Column struct {
	sortable.Sortable
	// Name represents the column name that will be used for sorting,
	// and as a default table header.
	Name string
	// DisplayName represents the table header visible in the printed table.
	DisplayName string
	Hidden      bool
}

Column represents the data structure of a table column.

func (*Column) GetHeader

func (c *Column) GetHeader() string

GetHeader gets the table header for the current column.

type Table

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

Table represents a data structure that can hold and display the contents of a table.

func New

func New() Table

New creates a new Table.

func (*Table) GetColumnByName

func (t *Table) GetColumnByName(n string) (int, Column, error)

GetColumnByName fetches the index and data structure of a column, by knowing its name.

func (*Table) GetColumnNameFromInitials

func (t *Table) GetColumnNameFromInitials(i string) (string, error)

GetColumnNameFromInitials matches a given input with a name of an existent column, without caring about casing, or if the given input is the complete name of the column.

func (*Table) SetColumns

func (t *Table) SetColumns(c []Column)

SetColumns sets the table's columns.

func (*Table) SetRows

func (t *Table) SetRows(r [][]string)

SetRows sets the table's rows.

func (*Table) SortByColumnName

func (t *Table) SortByColumnName(n string, direction string) error

SortByColumnName sorts the table by a column name, in the given direction.

func (*Table) String

func (t *Table) String() string

String makes the Table data structure implement the Stringer interface, so we can easily pretty-print it.

Jump to

Keyboard shortcuts

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