util

package
v0.0.0-...-f852ded Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var After = func(t time.Time) bool {
	return time.Now().After(t)
}

After returns whether the current time is after t. It is stored in a variable so it can be mocked out for unit tests.

View Source
var AppFs = afero.NewOsFs()

AppFs is an aero filesystem. It is stored in a variable so that we can replace it with in-memory filesystems for unit tests.

View Source
var Sleep = time.Sleep

Sleep stores time.Sleep so we can mock it out for unit tests.

Functions

func BackoffWaitFor

func BackoffWaitFor(pred func() bool, cap time.Duration, timeout time.Duration) error

BackoffWaitFor waits until `pred` is satisfied, or `timeout` Duration has passed. Every time the predicate fails, double the sleep interval until `cap` is reached.

func FileExists

func FileExists(path string) (bool, error)

FileExists checks if the given path corresponds to an existing file in the Afero file system.

func GetNodeBinary

func GetNodeBinary() (string, error)

GetNodeBinary returns the name of the Node.js binary. Even though `node` is the blessed name for the Node.js binary, some package managers (e.g. apt-get) install the binary as `nodejs`. The `nodejs` name is used by package managers that already had a package named `node`, so to avoid accidentally executing the wrong `node` binary, we try the `nodejs` binary first.

func JoinNotifiers

func JoinNotifiers(notifiers ...chan struct{}) chan struct{}

JoinNotifiers merges a list of notifications channels. The returned channel will notify if one or more notifications have occurred on any of the channels since the last time it was checked.

func Mkdir

func Mkdir(path string, perm os.FileMode) error

Mkdir creates a new aero directory.

func MyIP

func MyIP() (string, error)

MyIP gets the local systems Public IP address as visible on the WAN by querying an external service.

func Open

func Open(path string) (afero.File, error)

Open opens a new aero file.

func PrintUsageString

func PrintUsageString(commands string, explanation string, flags *flag.FlagSet)

PrintUsageString formats and prints usage strings for cli commands.

func ReadFile

func ReadFile(filename string) (string, error)

ReadFile returns the contents of `filename`.

func RemoveAll

func RemoveAll(path string) error

RemoveAll deletes the entire directory tree rooted at path.

func ShortUUID

func ShortUUID(uuid string) string

ShortUUID truncates a uuid string to 12 characters.

func Stat

func Stat(path string) (os.FileInfo, error)

Stat returns file info on the given path.

func ToTar

func ToTar(name string, permissions int, content string) (io.Reader, error)

ToTar returns a tar archive named NAME and containing CONTENT.

func Walk

func Walk(root string, walkFn filepath.WalkFunc) error

Walk performs a traversal of the directory tree rooted at root.

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile writes 'data' to the file 'filename' with the given permissions.

Types

type EventTimer

type EventTimer struct {
	// contains filtered or unexported fields
}

EventTimer is a utility struct that allows us to time how long loops take, as well as how often they are triggered.

func NewEventTimer

func NewEventTimer(eventName string) *EventTimer

NewEventTimer creates and returns a ready to use EventTimer

func (*EventTimer) LogEnd

func (ltl *EventTimer) LogEnd()

LogEnd logs the end of a loop and how long it took to run.

func (*EventTimer) LogStart

func (ltl *EventTimer) LogStart()

LogStart logs the start of a loop and how long it has been since the last trigger.

type Formatter

type Formatter struct{}

Formatter implements the log formatter for Kelda.

func (Formatter) Format

func (f Formatter) Format(entry *log.Entry) ([]byte, error)

Format converts a logrus entry into a string for logging.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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