util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout default timeout for most operations
	DefaultTimeout = 10 * time.Minute

	// DownloadTimeout is the configured download timeout after which the run is aborted
	DownloadTimeout = 30 * time.Minute

	// PortAvailableTimeout timeout used while waiting for a port to become available
	PortAvailableTimeout = 30 * time.Minute

	// LongCreationTimeout timeout to use for longer operations
	LongCreationTimeout = 60 * time.Minute

	// ServiceStartedTimeout timeout used while waiting for a service to be started
	ServiceStartedTimeout = 1 * time.Minute
)

Variables

This section is empty.

Functions

func BurnAfterReading

func BurnAfterReading(file *os.File)

BurnAfterReading ensure a consumed file is closed and deleted

func DownloadFile

func DownloadFile(url string) (destFile *os.File, finalErr error)

DownloadFile downloads the specified url to a temporary location

func IsValidEmailAddress

func IsValidEmailAddress(email string) bool

IsValidEmailAddress returns true if the passed string is a valid email address

func LogError

func LogError(action func() error)

LogError logs any errors returned by the action

func LogNonNilError

func LogNonNilError(err error)

LogNonNilError logs the error if not nil

func MergeErrors

func MergeErrors(message string, newError error, previousError error) error

MergeErrors constructs a new error based on a description string, given error, and a potentially previously existing error TODO(mihaibojin): https://godoc.org/gopkg.in/errgo.v2/fmt/errors

func PanicOnError

func PanicOnError(action func() error)

PanicOnError panics when the action is run and results in an error

func PanicOnNonNilErr

func PanicOnNonNilErr(err error)

PanicOnNonNilErr convenience wrapper which panics when the passed error is not nil

func ReadAllIntoTempFile

func ReadAllIntoTempFile(src io.Reader, pattern string) (file *os.File, err error)

ReadAllIntoTempFile reads all available data and saves it into a temporary file, using the specified pattern to identify it on the file system returns a file ready for reading

func ReopenFile

func ReopenFile(file *os.File) (*os.File, error)

ReopenFile reopens the file specified by the passed file descriptor, for reading

func SyncAndCloseFunc

func SyncAndCloseFunc(file *os.File, topError *error)

SyncAndCloseFunc returns a function which can be passed to defer to sync and close the file, thus ensuring all data was saved on disk, or outlining any problems with the underlying file-system this implementation is loosely based on https://www.joeshaw.org/dont-defer-close-on-writable-files/ and https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md

func TryExtractFirstLastNameAndEmail

func TryExtractFirstLastNameAndEmail(contents string) (firstName string, lastName string, emailAddress string)

TryExtractFirstLastNameAndEmail attempts to extract first, last name and email address

  • if the passed contents are not an email, both the first/last names will be set to the specified value and the email will be left blank

if the email address does not contain a separator character, its user part will be set to both first/last name values if the email address has a dot or underscore separator character, the first name will be set to

the string up to the separator and the last name will be set to the character string starting after the separator

Types

This section is empty.

Jump to

Keyboard shortcuts

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