common

package
v0.0.0-...-2aa8b88 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCommandExecutionTimeout = errors.New("command execution timeout exceeded")
View Source
var ErrorCustomRootCertPoolNotImplementedForOS = fmt.Errorf("not implemented for current os")

Functions

func CustomRootCertPool

func CustomRootCertPool() (*x509.CertPool, error)

func FloatToIntRoundUP

func FloatToIntRoundUP(f float64) int

func GetEnv

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

GetEnv retrieves the environment variable key. If it does not exist it returns the default.

func HostProc

func HostProc(combineWith ...string) string

func HostSys

func HostSys(combineWith ...string) string

func LogOncef

func LogOncef(logLevel logrus.Level, format string, args ...interface{})

LogOncef logs message only once using standard logger hashes the serialized list of all parameters to check if message was already logged

func MergeStringMaps

func MergeStringMaps(mapA, mapB map[string]interface{}) map[string]interface{}

func ReadLines

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

ReadLines reads contents from a file and splits them by new lines. A convenience wrapper to ReadLinesOffsetN(filename, 0, -1). from github.com/shriou/gopsutil/internal/common.go

func ReadLinesOffsetN

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

ReadLines reads contents from file and splits them by new line. from github.com/shriou/gopsutil/internal/common.go 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 RoundToTwoDecimalPlaces

func RoundToTwoDecimalPlaces(v float64) float64

func RunCommandInBackground

func RunCommandInBackground(name string, arg ...string) ([]byte, error)

RunCommandInBackground convenience wrapper to RunCommandWithContext

func RunCommandWithContext

func RunCommandWithContext(ctx context.Context, name string, arg ...string) ([]byte, error)

RunCommandWithContext convenience wrapper to CommandWithContext

func RunCommandWithTimeout

func RunCommandWithTimeout(timeout time.Duration, name string, arg ...string) ([]byte, error)

RunCommandWithTimeout runs command and returns it's standard output. If timeout exceeded the returned error is ErrCommandExecutionTimeout

func StrInSlice

func StrInSlice(search string, slice []string) bool

StrInSlice returns true if search string found in slice

Types

type ErrorCollector

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

ErrorCollector type allows accumulation of errors in one place and operating on them as a single error.

func (*ErrorCollector) Add

func (c *ErrorCollector) Add(err error)

Add adds error to collection if err is not nil

func (*ErrorCollector) Combine

func (c *ErrorCollector) Combine() error

Combine returns all collected errors as a single error

func (*ErrorCollector) HasErrors

func (c *ErrorCollector) HasErrors() bool

HasErrors returns true if there were any errors collected

func (*ErrorCollector) String

func (c *ErrorCollector) String() string

String returns string representation of ErrorCollector (all errors concatenated)

type Invoke

type Invoke struct{}

func (Invoke) CommandWithContext

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

type Invoker

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

Invoker executes command in context and gathers stdout/stderr output into slice

type MeasurementsMap

type MeasurementsMap map[string]interface{}

func (MeasurementsMap) AddInnerWithPrefix

func (mm MeasurementsMap) AddInnerWithPrefix(prefix string, m MeasurementsMap) MeasurementsMap

func (MeasurementsMap) AddWithPrefix

func (mm MeasurementsMap) AddWithPrefix(prefix string, m MeasurementsMap) MeasurementsMap

type Timestamp

type Timestamp time.Time

Timestamp type allows marshaling time.Time struct as Unix timestamp value

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(raw []byte) error

Jump to

Keyboard shortcuts

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