util

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBuffer          = 65535
	FilePerms          = 0666
	QemuImgCmd         = "qemu-img"
	DockerCmd          = "docker"
	QemuImgContainer   = "ghcr.io/hellt/qemu-img:latest"
	ISOBinary          = "genisoimage"
	DarwinISOBinary    = "mkisofs"
	ISOBinaryContainer = "ghcr.io/hellt/cdrkit:1.11.11-r3"
)

Variables

View Source
var ErrAllocationError = errors.New("allocationError")

ErrAllocationError is an error returned when boxen encounters an issue allocating resources to a virtual machine.

View Source
var ErrCommandError = errors.New("commandError")

ErrCommandError is an error returned when a command fails to execute.

View Source
var ErrConsoleError = errors.New("consoleError")

ErrConsoleError is an error returned when connecting to a device console produces an error, or when a console operation fails.

View Source
var ErrIgnoredOption = errors.New("ignoredOption")

ErrIgnoredOption is an error returned when any option is not applicable for the given operation -- when this error is returned it is *usually* safe to ignore.

View Source
var ErrInspectionError = errors.New("inspectionError")

ErrInspectionError is an error returned when an issue "inspecting" an instance is encountered.

View Source
var ErrInstanceError = errors.New("instanceError")

ErrInstanceError is an error returned when a "well-formed"/created instance (as in, an instance that gets to the point of starting) encounters an error.

View Source
var ErrProvisionError = errors.New("provisionError")

ErrProvisionError is an error returned when provisioning a virtual machine in the local configuration fails.

View Source
var ErrValidationError = errors.New("validationError")

ErrValidationError is an error returned when validating provided information, usually from a user, is encountered.

Functions

func AllStringVal added in v0.0.1

func AllStringVal(val string, s ...string) bool

AllStringVal returns true if all strings in variadic s matches the string val.

func AnyStringVal added in v0.0.1

func AnyStringVal(val string, s ...string) bool

AnyStringVal returns true if any string in variadic s matches the string val.

func ApplyTimeoutMultiplier

func ApplyTimeoutMultiplier(timeout int) int

ApplyTimeoutMultiplier returns the timeout, as an integer, after being multiplied by the environment variable BOXEN_TIMEOUT_MULTIPLIER.

func AvailableAccel

func AvailableAccel() []string

func ByteSliceAllNull

func ByteSliceAllNull(b []byte) bool

ByteSliceAllNull checks if a byte slice contains onlyl null bytes.

func ByteSliceContains

func ByteSliceContains(b [][]byte, l []byte) bool

ByteSliceContains checks if slice of bytes contains a given byte subslice.

func CommandExists added in v0.0.2

func CommandExists(cmd string) bool

CommandExists checks if a command `cmd` exists in the PATH.

func ConfigLinesMd5Password added in v0.0.2

func ConfigLinesMd5Password(lines []string, passwordPattern *regexp.Regexp) []string

ConfigLinesMd5Password accepts a slice of config lines and replaces the plain-text password with a md5 encrypted password. It does this by using the provided passwordPattern to find lines that contain passwords.

func CopyAsset

func CopyAsset(s, d string) error

CopyAsset copies an asset file source `s` to destination `d`.

func CopyFile

func CopyFile(s, d string) error

CopyFile copies a file source `s` to destination `d`.

func DirectoryExists

func DirectoryExists(d string) bool

DirectoryExists checks if a given path exists (and is a directory).

func ExpandPath

func ExpandPath(p string) string

ExpandPath expands user home path in provided path p.

func FileExists

func FileExists(f string) bool

FileExists checks if a given file exists (and is not a directory).

func GetEnvIntOrDefault

func GetEnvIntOrDefault(k string, d int) int

func GetEnvStrOrDefault

func GetEnvStrOrDefault(k, d string) string

func GetPreferredIP

func GetPreferredIP() string

GetPreferredIP returns the IP address the host machine prefers for outbound requests.

func GetQemuPath

func GetQemuPath() string

func GetTimeoutMultiplier

func GetTimeoutMultiplier() int

GetTimeoutMultiplier returns either 1, or the integer value of the environment variable BOXEN_TIMEOUT_MULTIPLIER.

func IntSliceContains

func IntSliceContains(s []int, i int) bool

IntSliceContains is a convenience function to check if a provided int i is in an int slice s.

func IntSliceUniqify

func IntSliceUniqify(s []int) []int

IntSliceUniqify removes any duplicated entries in a slice of integers s.

func Md5Crypt

func Md5Crypt(password []byte) []byte

Md5Crypt "encrypts" a provided password byte slice. This is *not* good encryption by any stretch! This exists in this library to encrypt plain text passwords for JunOS such that they can be sent to the JunOS device(s) over telnet without requiring any prompting.

func ResolveFile

func ResolveFile(f string) (string, error)

ResolveFile resolves provided file path.

func StringSliceContains

func StringSliceContains(s string, l []string) bool

StringSliceContains checks if slice of strings contains a given string.

Types

type LockingWriterReader

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

LockingWriterReader is a simple type that satisfies io.Writer, but also allows for reads. It does this with a lock as well, so it is safe to use with long-running commands. It also allows for reading from stderr (for example) while the process is still running without any race issues.

func NewLockingWriterReader

func NewLockingWriterReader() *LockingWriterReader

NewLockingWriterReader returns a new instance of LockingWriterReader.

func (*LockingWriterReader) Read

func (lw *LockingWriterReader) Read() ([]byte, error)

Read safely reads (with a rlock) from the buffer in LockingWriterReader instance.

func (*LockingWriterReader) Write

func (lw *LockingWriterReader) Write(b []byte) (n int, err error)

Write safely writes (with a lock) to the buffer in LockingWriterReader instance.

type Spinner

type Spinner struct {
	Delay time.Duration

	Prefix string
	Suffix string

	PostUpdate func(s *Spinner)
	Finale     func(s *Spinner) string
	// contains filtered or unexported fields
}

func NewSpinner

func NewSpinner() *Spinner

func (*Spinner) Start

func (s *Spinner) Start()

func (*Spinner) Stop

func (s *Spinner) Stop()

Jump to

Keyboard shortcuts

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