results

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 7 Imported by: 0

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

func GenericSortInterface(slice interface{}, sortColumn string, sortDescending bool)

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.

Jump to

Keyboard shortcuts

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