util

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package util provides miscellaneous utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeNice

func BeNice(priority int) error

BeNice lets a Unix process reduce its own execution priority to avoid impacting other processes. Positive values have lower privilege (are nicer) while negative values have a higher privilege (are MEAN!).

func Extract added in v0.5.8

func Extract(pathname string, content []byte, data any) error

func IsTTY added in v0.5.0

func IsTTY(f *os.File) bool

IsTTY determines if a file handle is attached to a TTY.

func LogRecover

func LogRecover()

LogRecover helps ensure any unhandled errors are logged. Useful as a `defer` function immediately upon entering a goroutine.

Types

type CommandLogger added in v0.5.3

type CommandLogger struct {
	Log func(string)
	// contains filtered or unexported fields
}

CommandLogger is used when newline-terminated output should be logged (e.g. from exec.Command).

func (*CommandLogger) Close added in v0.5.3

func (cl *CommandLogger) Close() error

Close implments io.WriteCloser by flushing any remaining string in the local buffer out to the logger and resets the buffer.

func (*CommandLogger) Write added in v0.5.3

func (cl *CommandLogger) Write(data []byte) (n int, err error)

Write implements io.Writer by buffering locally and logging each newline-terminated string found in the buffer.

type Woke added in v0.5.7

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

Woke is a utility to help know when a process was suspended for some amount of time.

func StartWokeWatch added in v0.5.7

func StartWokeWatch(delay time.Duration, diffMin time.Duration, onWake WokeFunc) *Woke

StartWokeWatch begins watching for conditions indicating when a time lapse has occurred. It will invoke onWake when the time difference detected is larger than diffMin, checking for lapses once every delay.

func (*Woke) Stop added in v0.5.7

func (w *Woke) Stop()

Stop will terminate the watcher (if running).

type WokeFunc added in v0.5.7

type WokeFunc func(diff time.Duration)

WokeFunc is the callback invoked when a time lapse is detected.

Jump to

Keyboard shortcuts

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