common

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Timeout                = 3 * time.Second
	ErrNotImplementedError = errors.New("not implemented yet")
	ErrTimeout             = errors.New("command timed out")
)

Functions

func ByteToString

func ByteToString(orig []byte) string

func GetEnv

func GetEnv(key string, dfault string, combineWith ...string) string

func GetEnvWithContext

func GetEnvWithContext(ctx context.Context, key string, dfault string, combineWith ...string) string

func HexToUint32

func HexToUint32(hex string) uint32

func HostDev

func HostDev(combineWith ...string) string

func HostDevWithContext

func HostDevWithContext(ctx context.Context, combineWith ...string) string

func HostEtc

func HostEtc(combineWith ...string) string

func HostEtcWithContext

func HostEtcWithContext(ctx context.Context, combineWith ...string) string

func HostProc

func HostProc(combineWith ...string) string

func HostProcMountInfoWithContext

func HostProcMountInfoWithContext(ctx context.Context, combineWith ...string) string

func HostProcWithContext

func HostProcWithContext(ctx context.Context, combineWith ...string) string

func HostRoot

func HostRoot(combineWith ...string) string

func HostRootWithContext

func HostRootWithContext(ctx context.Context, combineWith ...string) string

func HostRun

func HostRun(combineWith ...string) string

func HostRunWithContext

func HostRunWithContext(ctx context.Context, combineWith ...string) string

func HostSys

func HostSys(combineWith ...string) string

func HostSysWithContext

func HostSysWithContext(ctx context.Context, combineWith ...string) string

func HostVar

func HostVar(combineWith ...string) string

func HostVarWithContext

func HostVarWithContext(ctx context.Context, combineWith ...string) string

func IntContains

func IntContains(target []int, src int) bool

func IntToString

func IntToString(orig []int8) string

func IsContainerized

func IsContainerized() (bool, error)

func ParseFloat

func ParseFloat(s string) float64

func ParseUint64

func ParseUint64(s string) uint64

func PathExists

func PathExists(filename string) bool

func PathExistsWithContents

func PathExistsWithContents(filename string) bool

func ReadFile

func ReadFile(filename string) (string, error)

func ReadFileNoStat

func ReadFileNoStat(filename string) ([]byte, error)

ReadFileNoStat uses ioutil.ReadAll to read contents of entire file. This is similar to ioutil.ReadFile but without the call to os.Stat, because many files in /proc and /sys report incorrect file sizes (either 0 or 4096). Reads a max file size of 512kB. For files larger than this, a scanner should be used.

func ReadInts

func ReadInts(filename string) ([]int64, error)

func ReadLine

func ReadLine(filename string, prefix string) (string, error)

ReadLine reads a file and returns the first occurrence of a line that is prefixed with prefix.

func ReadLines

func ReadLines(filename string) ([]string, error)

func ReadLinesOffsetN

func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error)

ReadLinesOffsetN reads contents from file and splits them by new line. The offset tells at which line number to start. The count determines the number of lines to read (starting from offset): n >= 0: at most n lines n < 0: whole file

func Round

func Round(val float64, n int) float64

func Sleep

func Sleep(ctx context.Context, interval time.Duration) error

func StringsContains

func StringsContains(target []string, src string) bool

func StringsHas

func StringsHas(target []string, src string) bool

func UintToString

func UintToString(orig []uint8) string

Types

type FakeInvoke

type FakeInvoke struct {
	Suffix string
	Error  error
}

func (FakeInvoke) Command

func (i FakeInvoke) Command(name string, arg ...string) ([]byte, error)

func (FakeInvoke) CommandWithContext

func (i FakeInvoke) CommandWithContext(_ context.Context, name string, arg ...string) ([]byte, error)

type Invoke

type Invoke struct{}

func (Invoke) Command

func (i Invoke) Command(name string, arg ...string) ([]byte, error)

func (Invoke) CommandWithContext

func (i Invoke) CommandWithContext(ctx context.Context, name string, arg ...string) ([]byte, error)

type Invoker

type Invoker interface {
	Command(string, ...string) ([]byte, error)
	CommandWithContext(context.Context, string, ...string) ([]byte, error)
}

Jump to

Keyboard shortcuts

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