utils

package
v0.0.0-...-71c6e05 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMissingValues

func AddMissingValues(target interface{}, source interface{}, ignoredFields ...string)

AddMissingValues iterates over the exported fields of the source object. For each such fields it checks whether the target object contains a field with the same name. If that is the case and if the target field does not yet have a value set, then the value from the source object is copied over.

func Assert

func Assert(cond bool, i interface{})

Assert will throw a panic if condition is false. The additional parameter is provided to panic() as argument.

func AssertNoError

func AssertNoError(err error)

AssertNoError is a cheap function to check for err==nil and panics if condition is not met

func CheckFieldsAreInRange

func CheckFieldsAreInRange(obj interface{}, min, max float64, fieldNames ...string) (err error)

CheckFieldsAreInRange checks that all provided struct fields are within a given range.

func CheckFieldsAreSet

func CheckFieldsAreSet(obj interface{}, fieldNames ...string) (err error)

CheckFieldsAreSet checks whether all provided struct fields have a non-zero value.

func Contains

func Contains(list []string, element string) (result bool)

Contains checks whether a list of strings contains a specific string.

func CopyFloat

func CopyFloat(in *float64) (out *float64)

CopyFloat creates a copy of a referenced float and returns the result as pointer.

func CopyString

func CopyString(in *string) (out *string)

CopyString creates a copy of a referenced string and returns the result as pointer.

func ExitOnError

func ExitOnError(err error, errMsg string, v ...interface{})

ExitOnError exits the program with rc=1 if err!=nil. The following Message and all additional arguments will be passed to fmt.Printf()

func ExitWithMessage

func ExitWithMessage(errMsg string, v ...interface{})

ExitWithMessage prints out a message on StdErr and then exits the program with rc=1

func GenericFieldsCheck

func GenericFieldsCheck(obj interface{}, isOk func(interface{}) bool, fieldNames ...string) (err error)

GenericFieldsCheck provides a generic way to check multiple fields of a struct at once.

func GetExecutableDir

func GetExecutableDir() (dirName string)

GetExecutableDir returns the dir in which the binary of this program is located

func GetTempDir

func GetTempDir() (dirName string)

GetTempDir returns the location of a temporary directory in which files can be stored. The caller needs to ensure that the directory is deleted afterwards.

func HasWhitespace

func HasWhitespace(s string) bool

HasWhitespace checks if a string includes at least one whitespace character

func InformOnError

func InformOnError(err error, errMsg string, v ...interface{})

InformOnError provides an error message on stdErr if an error occurs, but continues with the program

func IsDir

func IsDir(dirname string) (exists bool, err error)

IsDir checks wether a directory exists.

func IsExported

func IsExported(val reflect.Value) bool

IsExported takes a reflection value and checks whether that is an exported field in a struct. Well, we cannot check here whether this is a struct field, but under the assumption that it was one, we can check whether it is exported then. Yay!

func IsFile

func IsFile(filename string) (exists bool, err error)

IsFile checks wether a file exists and is not a directory.

func IsSet

func IsSet(val interface{}) (result bool)

IsSet checks whether the provided value is different from its zero value for element types and different from nil for pointer type.s

func IsTestEnvironment

func IsTestEnvironment() bool

IsTestEnvironment should indicate whether the current run is a test run.

func OpenWithDefaultViewer

func OpenWithDefaultViewer(file string) (err error)

OpenWithDefaultViewer opens the provided file with the default viewer registered in the system for this.

func QuoteStringIfRequired

func QuoteStringIfRequired(s string) string

QuoteStringIfRequired takes a string as input. If the string contains whitespace, then it is returned enclosed by quotation marks, else it is returned as-is

func ReadFileToLines

func ReadFileToLines(filename string) (lines []string, err error)

ReadFileToLines reads in the given file and returns the content as string array of lines

func SetIsTestEnvironment

func SetIsTestEnvironment(isTestEnv bool)

SetIsTestEnvironment sets a flag that indicates that we are currently in a test environment.

func SortCoords

func SortCoords(c1, c2 float64) (float64, float64)

SortCoords takes two coordinates and returns them ordered from large to small

func SplitAndTrim

func SplitAndTrim(input, sep string) (result []string)

SplitAndTrim splits the string up at the provided separator and them trims each substring.

func ToCommaSeparatedString

func ToCommaSeparatedString(input []string) (result string)

ToCommaSeparatedString takes a list of input values and returns them as single string with all values separated by commas.

func UnquoteStringIfRequired

func UnquoteStringIfRequired(s string) string

UnquoteStringIfRequired takes a string as input. If the string is enclosed in quotation marks, then these are removed in the returned string

Types

This section is empty.

Jump to

Keyboard shortcuts

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