util

package
v0.0.0-...-a4a517a Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Debug is whether the debug output is enabled or not.
	Debug = false
)

Functions

func Ar

func Ar(a ...string) []string

func AssertFileExist

func AssertFileExist(t *testing.T, file string)

func AssertStringSlicesEqual

func AssertStringSlicesEqual(t *testing.T, input string, expected []string, actual []string)

func AssertStringsEqual

func AssertStringsEqual(t *testing.T, input string, expected string, actual string)

func Check

func Check(err error, format string, a ...interface{})

func CompressSlash

func CompressSlash(file string) string

func Debugf

func Debugf(format string, a ...interface{})

func DebugfForce

func DebugfForce(format string, a ...interface{})

func Dump

func Dump(prefix string, obj interface{})

func Encode

func Encode(args []string) string

Encode a string array into a single command string.

func Exit

func Exit(success bool)

Exit should be used within RunAndExit to cleanly finishes the process.

func ExitFailure

func ExitFailure()

ExitFailure should be used within RunAndExit to cleanly finishes the process with a failure code.

func ExitSuccess

func ExitSuccess()

ExitSuccess should be used within RunAndExit to cleanly finishes the process with a success code.

func Fatalf

func Fatalf(format string, a ...interface{})

func FilenameSafe

func FilenameSafe(s string) string

func FindZenlogBin

func FindZenlogBin() string

FindZenlogBin returns the fullpath of the zenlog executable.

func FindZenlogBinDir

func FindZenlogBinDir() string

FindZenlogBinDir returns the fullpath of the directory where the zenlog executable is.

func Fingerprint

func Fingerprint() string

Create a random string.

func GetInjectedNow

func GetInjectedNow(clock utils.Clock) time.Time

GetInjectedNow returns an injected time if _ZENLOG_TIME_INJECTION_FILE is set, or otherwise just returns a passed Clock.

func GetIntEnv

func GetIntEnv(name string, def int) int

GetIntEnv extracts an integer from an environmental variable.

func GetSubcommand

func GetSubcommand() (command string, args []string)

GetSubcommand extracts a zenlog subcommand name from os.Args.

func MustExec

func MustExec(args []string)

MustExec is a must-version of syscall.Exec.

func MustMarshal

func MustMarshal(v interface{}) string

MustMarshal is a must version of json.Marshal.

func MustUnmarshal

func MustUnmarshal(data string, v interface{})

MustUnmarshal is a must version of json.Unmarshal.

func NumLines

func NumLines(data []byte) int

Return number of LFs in bytes.

func PropagateTerminalSize

func PropagateTerminalSize(from *os.File, to *os.File) error

func ReadFromFile

func ReadFromFile(filename string, predicate func(vals []string) bool, timeout time.Duration) ([]string, error)

ReadFromFile read encoded args from a file. The predicate callback can be used to tell whether a received set of args is what's expected or not.

func RunAndExit

func RunAndExit(f func() int)

RunAndExit executes a given function. Within the function, util.Exit* functions can be used to finish the process cleanly.

func Say

func Say(format string, a ...interface{})

func SetOutputIsRaw

func SetOutputIsRaw(raw bool)

SetOutputIsRaw sets whether stdout is in raw mode or not.

func SlicesEqual

func SlicesEqual(a []string, b []string) bool

func StartEmergencyShell

func StartEmergencyShell()

StartEmergencyShell exec's /bin/sh.

func TryDecodeBytes

func TryDecodeBytes(s []byte) (success bool, prefix []byte, args []string)

TryDecodeBytes extracts a command string from a given string, and return the prefix part (i.e. the part followed by the command string) and the split up command arguments.

func TryUnmarshal

func TryUnmarshal(data string, v interface{}) bool

TryUnmarshal is a json.Unmarshal wrapper that returns whether succeeded or not.

func Tty

func Tty() string

func Ttyname

func Ttyname(fd uintptr) string

func Warn

func Warn(err error, format string, a ...interface{}) bool

func WriteToFile

func WriteToFile(filename string, args []string) error

WriteToFile writes encoded args to a file.

func ZenlogBinCtime

func ZenlogBinCtime() time.Time

ZenlogBinCtime returns the ctime of the zenlog executable.

Types

This section is empty.

Jump to

Keyboard shortcuts

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