utils

package
v0.0.0-...-a4c2a2d Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Purple = color.ColorFunc("magenta+h")
	Red    = color.ColorFunc("red+h")
	Blue   = color.ColorFunc("blue+h")
	Bold   = color.ColorFunc("default+b")
)

Functions

func AssertTestCase

func AssertTestCase(t *testing.T, object interface{}, theCase TestCase)

func AssertTestCases

func AssertTestCases(t *testing.T, collection TestCollection)

func CheckError

func CheckError(err error, message string)

CheckError will exit upon the presence of an error, showing a message upon error

func DoesFileExist

func DoesFileExist(name string) bool

DoesFileExist returns if the given file exists on disk

func Exit

func Exit(rc int)

Exit with the given return code, gracefully cleaning up

func ExitWithErrorMessage

func ExitWithErrorMessage(msg string)

ExitWithErrorMessage will exit with return code 1 and output an error message

func FormatDuration

func FormatDuration(duration time.Duration) string

FormatDuration outputs a given duration in HH:MM:SS

func GetFilenameFromUrl

func GetFilenameFromUrl(urlStr string) string

todo: return error and have caller handle GetFilenameFromUrl extracts the postfix filename from a given URL

func GetSudoPasswd

func GetSudoPasswd() string

todo: return error and have caller handle

func InterfaceSlice

func InterfaceSlice(slice interface{}) []interface{}

func Load

func Load(path string, object interface{}) error

Load decodes via Gob the contents of the given file to an object

func Md5OfFile

func Md5OfFile(filepath string) string

todo: return error and have caller handle Md5OfFile returns the Md5 sum of a file given the path to the file

func MinMax

func MinMax(array []float64) (float64, float64, error)

MinMax returns the min and max values from an array of float64 values

func RemoveOneValue

func RemoveOneValue(slice []float64, value float64) []float64

RemoveOneValue removes the first matching value from the given array of float64 values

func Save

func Save(path string, object interface{}) error

Save encodes a generic object via Gob to the given file path

func TrimToVisualLength

func TrimToVisualLength(message string, length int) string

TrimToVisualLength truncates the given message to the given length (taking into account ansi escape sequences)

func VerifyOrCreate

func VerifyOrCreate(path string) error

Checks if specified directory exists and, if it doesn't, create it

func VisualLength

func VisualLength(str string) int

VisualLength determines the length of a string (taking into account ansi control sequences)

Types

type TestCase

type TestCase struct {
	Name          string
	ExpectedValue interface{}
	ActualValue   interface{}
	ActualName    string
	Index         int
}

type TestCollection

type TestCollection struct {
	Collection []interface{}
	Cases      []TestCase
}

Jump to

Keyboard shortcuts

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