util

package
v0.0.0-...-8d9275d Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateViaTempMove

func CreateViaTempMove(path, tempDir, prefix string, fn func(w io.Writer) error) error

CreateViaTempMove atomically writes a file containing content to path.

In order to do this atomically, we first create the file in a temporary directory and, upon success, move it into place via an atomic move.

On failure, cleanup is best-effort.

func ForEachFile

func ForEachFile(path string, fn func(os.FileInfo) error) error

ForEachFile iterates over every file in the specified directory path, invoking fn for each identified file.

If path is not a directory, ForEachFile will return an error.

If fn returns an error, iteration will stop and ForEachFile will return that error.

func LoopUntil

func LoopUntil(c context.Context, p time.Duration, fn func(context.Context) error) error

LoopUntil runs the function fn periodically, every p, until the Context is cancelled or the function returns an error. fn will run immediately, and then periodicalkly after that.

If fn returns an error, LoopUntil will terminate immediately and return that error. Otherwise, LoopUntil will return the Context's cancellation error.

func Sleep

func Sleep(c context.Context, d time.Duration) error

Sleep is a shortcut for a single-use Sleeper.

Types

type Application

type Application struct {
	// Verbosity is the logging verbosity level.
	Verbosity zapcore.Level

	// Production, if true, means to run in production logging mode.
	Production bool

	// ColorizeLogs, if true, allows the application to colorize its logs.
	ColorizeLogs bool

	// LogPath, if not nil, is a path to output logs to.
	LogPath string

	// Profiler is the configured profiler to use.
	Profiler profiling.Profiler
}

Application is a configuration for a generic application entry point.

Application will set up a basic Context, signal handler, and run an execute method.

func (*Application) AddFlags

func (a *Application) AddFlags(fs *pflag.FlagSet)

AddFlags adds application-level flags to fs.

func (*Application) Run

func (a *Application) Run(c context.Context, fn func(context.Context) error)

Run runs the Application in a generic harness.

It creates a derivative Context from c which will be cancelled when/if a signal is encountered. It also installs a logger.

If the callback returns a non-nil error, Run will exit with a status of 1 and log the error.

type Hex

type Hex []byte

Hex is a byte slice that encodes as a hex-dumped string.

It can be used for easy lazy hex dumping.

func (Hex) String

func (h Hex) String() string

type Sleeper

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

Sleeper is a device that facilitates Context-cancellable sleeping.

Sleeper is not safe for concurrent usage.

func (*Sleeper) Close

func (s *Sleeper) Close()

Close closes the Sleeper, releasing any resources that it owns.

Close is optional, but may offer better resource management if called.

func (*Sleeper) Sleep

func (s *Sleeper) Sleep(c context.Context, d time.Duration) error

Sleep sleeps until either the specified period, d, has expired, or the supplied Context has been cancelled.

If Sleep exits naturally, it will return nil. Otherwise, if it is cancelled prematurely, the Context's error will be returned.

type StringSlice

type StringSlice struct {
	S     []string
	Delim string
}

StringSlice lazily renders to a Delim-delimited string.

func (*StringSlice) String

func (ss *StringSlice) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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