util

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MPL-2.0 Imports: 7 Imported by: 13

Documentation

Overview

Package util contains utility functions

Package util contains utility functions

Package util contains utility functions

Package util contains utility functions

Index

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

func IsErrorBool(err error) (b bool)

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

func PrintErrf(f string, err error)

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

func PrintInfof(f string, a ...any)

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

func PrintSuccessf(f string, a ...any)

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

func PrintTabbedf(f string, a ...any)

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

func PrintWarningf(f string, a ...any)

PrintWarningf Prints a warning message with a yellow indicator to STDOUT when passed a format

Types

This section is empty.

Jump to

Keyboard shortcuts

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