util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: MIT Imports: 14 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 FileExists

func FileExists(path string) (bool, error)

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

func MapAsString

func MapAsString(m map[string]string) string

MapAsString creates a deterministic string representing the given map.

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 exeternal service.

func Open

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

Open opens a new aero file.

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 StrSliceEqual

func StrSliceEqual(x, y []string) bool

StrSliceEqual returns true of the string slices 'x' and 'y' are identical.

func StrStrMapEqual

func StrStrMapEqual(x, y map[string]string) bool

StrStrMapEqual returns true of the string->string maps 'x' and 'y' are equal.

func ToTar

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

ToTar returns a tar archive named NAME and containing CONTENT.

func WaitFor

func WaitFor(pred func() bool, interval time.Duration, timeout time.Duration) error

WaitFor waits until `pred` is satisfied, or `timeout` Duration has passed, checking at every `interval`.

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 Quilt.

func (Formatter) Format

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

Format converts a logrus entry into a string for logging.

Jump to

Keyboard shortcuts

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