Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenericRenderResultsTableInterface ¶
func GenericRenderResultsTableInterface(slice interface{}, totalValues map[string]interface{})
GenericRenderResultsTableInterface renders a table from a slice of structs or maps. It takes a slice of interface{} and a map of string to interface{} representing the total values. The function uses reflection to determine the headers and fields based on the struct or map keys. It then creates a table, appends the header and rows, and optionally appends the footer with total values. Finally, it renders the table using the pterm library.
Example usage:
type Person struct { Name string Age int } people := []Person{ {Name: "John", Age: 30}, {Name: "Jane", Age: 25}, } totalValues := map[string]interface{}{ "Age": 55, }
func GenericSortInterface ¶
GenericSortInterface sorts a slice of structs based on a specified field name. It takes three arguments:
slice: the slice of structs to be sorted sortColumn: the name of the field to sort by sortDescending: a boolean flag indicating whether to sort in descending order
The function uses reflection to access the specified field of each struct in the slice. It then sorts the slice using the sort.Slice function and a custom comparison function. The comparison function compares the values of the specified field for each pair of structs and returns true if the first value is less than the second value (for ascending order), or false otherwise. If sortDescending is true, the comparison is reversed.
The function supports sorting fields of type string, int, uint, and float. If the specified field is not found or has an unsupported type, the function returns without sorting.
Types ¶
This section is empty.