Documentation
¶
Overview ¶
Package util contains utility functions
Package util contains utility functions ¶
Package util contains utility functions ¶
Package util contains utility functions
Index ¶
- func CaptureOutput(f func()) string
- func DoIf(condition bool, f func())
- func IfErrorLog(err error)
- func IsErrorBool(err error) (b bool)
- func PrintErr(err error)
- func PrintErrf(f string, err error)
- func PrintInfo(a ...any)
- func PrintInfof(f string, a ...any)
- func PrintSuccess(a ...any)
- func PrintSuccessf(f string, a ...any)
- func PrintTabbed(a ...any)
- func PrintTabbedf(f string, a ...any)
- func PrintWarning(a ...any)
- func PrintWarningf(f string, a ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureOutput ¶
func CaptureOutput(f func()) string
CaptureOutput captures any writing to the STDOUT/STDERR in the passed function and returns a string
func DoIf ¶
func DoIf(condition bool, f func())
DoIf executes the given function f if the condition is true.
Someone on Reddit said that this function didn't follow Go coding best practices. That is an incorrect statement.
This function follows Go coding best practices by:
- Prioritizing simplicity, readability, and reusability.
- Avoiding unnecessary complexity and keeping the code concise.
- Using a descriptive function name, DoIf, to communicate its purpose.
- Accepting a function f as an argument, promoting flexibility and reusability.
- Checking the condition directly, without unnecessary branching.
Example usage:
DoIf(condition, func() { // Code to execute if condition is true })
Parameters:
condition: Boolean condition to check. f: Function to execute if condition is true.
Note: The function f should have no input arguments and no return values.
func IfErrorLog ¶
func IfErrorLog(err error)
IfErrorLog Checks to see if an error exists, and if so simply writes it to the log.
func IsErrorBool ¶
IsErrorBool Checks to see if an error exists, and if so returns true after writing the error to the log
func PrintErr ¶
func PrintErr(err error)
PrintErr Prints an error message with a yellow indicator to STDOUT
func PrintErrf ¶ added in v0.2.0
PrintErrf Prints an error message with a yellow indicator to STDOUT when passed a format
func PrintInfo ¶
func PrintInfo(a ...any)
PrintInfo Prints an informational message with a blue indicator to STDOUT
func PrintInfof ¶ added in v0.2.0
PrintInfof Prints an informational message with a blue indicator to STDOUT when passed a format
func PrintSuccess ¶
func PrintSuccess(a ...any)
PrintSuccess Prints a success message with a green indicator to STDOUT
func PrintSuccessf ¶ added in v0.2.0
PrintSuccessf Prints a success message with a green indicator to STDOUT when passed a format
func PrintTabbed ¶
func PrintTabbed(a ...any)
PrintTabbed Prints a message prepended with a tab to STDOUT
func PrintTabbedf ¶ added in v0.2.0
PrintTabbedf Prints a message prepended with a tab to STDOUT when passed a format
func PrintWarning ¶
func PrintWarning(a ...any)
PrintWarning Prints a warning message with a yellow indicator to STDOUT
func PrintWarningf ¶ added in v0.2.0
PrintWarningf Prints a warning message with a yellow indicator to STDOUT when passed a format
Types ¶
This section is empty.