utils

package
v0.0.0-...-acd7349 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2013 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FastInsecureHash = false

FastInsecureHash specifies whether a fast, insecure version of the hash algorithm will be used. Changing this will cause PasswordHash to produce incompatible passwords. It should only be changed for testing purposes - to make tests run faster.

Functions

func AptGetInstall

func AptGetInstall(packages ...string) error

AptGetInstall runs 'apt-get install packages' for the packages listed here

func ErrorContextf

func ErrorContextf(err *error, format string, args ...interface{})

ErrorContextf prefixes any error stored in err with text formatted according to the format specifier. If err does not contain an error, ErrorContextf does nothing.

func GetIPv4Address

func GetIPv4Address(addresses []net.Addr) (string, error)

GetIPv4Address iterates through the addresses expecting the format from func (ifi *net.Interface) Addrs() ([]net.Addr, error)

func Gunzip

func Gunzip(data []byte) ([]byte, error)

Gunzip uncompresses the given data.

func Gzip

func Gzip(data []byte) []byte

Gzip compresses the given data.

func IsValidUUIDString

func IsValidUUIDString(s string) bool

IsValidUUIDString returns true, if the given string matches a valid UUID (version 4, variant 2).

func NormalizePath

func NormalizePath(dir string) string

NormalizePath replaces a leading ~ with $HOME, and removes any .. or . path elements.

func PasswordHash

func PasswordHash(password string) string

PasswordHash returns base64-encoded one-way hash of the provided salt and password that is computationally hard to crack by iterating through possible passwords.

func RandomBytes

func RandomBytes(n int) ([]byte, error)

RandomBytes returns n random bytes.

func RandomPassword

func RandomPassword() (string, error)

RandomPassword generates a random base64-encoded password.

func ReadYaml

func ReadYaml(path string, obj interface{}) error

ReadYaml unmarshals the yaml contained in the file at path into obj. See goyaml.Unmarshal.

func ShQuote

func ShQuote(s string) string

ShQuote quotes s so that when read by bash, no metacharacters within s will be interpreted as such.

func Timeit

func Timeit(action string) func()

Start a timer, used for tracking time spent. Generally used with either defer, as in:

defer utils.Timeit("my func")()

Which will track how much time is spent in your function. Or if you want to track the time spent in a function you are calling then you would use:

toc := utils.Timeit("anotherFunc()")
anotherFunc()
toc()

This tracks nested calls by indenting the output, and will print out the full stack of timing when we reach the top of the stack.

func WriteYaml

func WriteYaml(path string, obj interface{}) error

WriteYaml marshals obj as yaml and then writes it to a file, atomically, by first writing a sibling with the suffix ".preparing" and then moving the sibling to the real path.

Types

type Attempt

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

func (*Attempt) Next

func (a *Attempt) Next() bool

Next waits until it is time to perform the next attempt or returns false if it is time to stop trying.

type AttemptStrategy

type AttemptStrategy struct {
	Total time.Duration // total duration of attempt.
	Delay time.Duration // interval between each try in the burst.
}

AttemptStrategy represents a strategy for waiting for an action to complete successfully.

func (AttemptStrategy) Start

func (a AttemptStrategy) Start() *Attempt

Start begins a new sequence of attempts for the given strategy.

type UUID

type UUID [16]byte

UUID represent a universal identifier with 16 octets.

func NewUUID

func NewUUID() (UUID, error)

NewUUID generates a new version 4 UUID relying only on random numbers.

func UUIDFromString

func UUIDFromString(s string) (UUID, error)

func (UUID) Copy

func (uuid UUID) Copy() UUID

Copy returns a copy of the UUID.

func (UUID) Raw

func (uuid UUID) Raw() [16]byte

Raw returns a copy of the UUID bytes.

func (UUID) String

func (uuid UUID) String() string

String returns a hexadecimal string representation with standardized separators.

Directories

Path Synopsis
On-disk mutex protecting a resource A lock is represented on disk by a directory of a particular name, containing an information file.
On-disk mutex protecting a resource A lock is represented on disk by a directory of a particular name, containing an information file.

Jump to

Keyboard shortcuts

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