util

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 142

Documentation

Index

Constants

View Source
const DefaultLogLevel = capnslog.INFO

Variables

This section is empty.

Functions

func AggregateErrors added in v1.7.1

func AggregateErrors(errs []error, format string, args ...interface{}) error

AggregateErrors takes a list of errors formats them into a pretty, user-readable list headed by the text "errors:". All errors in the list will lose any context besides their error string. If the errs list is empty, AggregateErrors returns nil. Example:

AggregateErrors(errList, "errors for my %q", "mom")  -->
`errors for my "mom":
    error 1
    error 2
    etc.`

func CreateTempFile added in v1.7.3

func CreateTempFile(content string) (*os.File, error)

CreateTempFile creates a temporary file with content passed as an argument

func PathToProjectRoot added in v1.5.7

func PathToProjectRoot() string

PathToProjectRoot returns the path to the root of the rook repo on the current host. This is primarily useful for tests.

func Retry added in v0.7.0

func Retry(maxRetries int, delay time.Duration, f func() error) error

Retry will attempt the given function until it succeeds, up to the given maximum amount of retries, sleeping for the given duration in between attempts.

func RetryWithTimeout added in v1.6.0

func RetryWithTimeout(f RetryFunc, period time.Duration, timeout time.Duration, description string) error

RetryWithTimeout retries the RetryFunc until the timeout occurs. It will retry once more after the timeout to avoid race conditions at the expense of running for slightly longer than timeout in the timeout/error case. The given description will be output in log/error messages as "... waiting for <description>..."

func SetGlobalLogLevel added in v1.8.0

func SetGlobalLogLevel(userLogLevelSelection string, logger *capnslog.PackageLogger)

func WriteFile

func WriteFile(filePath string, contentBuffer bytes.Buffer) error

func WriteFileToLog added in v0.3.0

func WriteFileToLog(logger *capnslog.PackageLogger, path string)

Types

type RetryFunc added in v1.6.0

type RetryFunc func() (done bool, err error)

RetryFunc is a function that returns true when it is done and it should be retried no longer. It should return error if there has been an error. The error will be logged if done==false (should keep retrying). The error will be returned by the calling function if done==true (should stop retrying).

Directories

Path Synopsis
Package exec embeds Rook's exec logic
Package exec embeds Rook's exec logic

Jump to

Keyboard shortcuts

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