utils

package
v0.0.0-...-f2d3d7a Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Second = time.Second
	Minute = Second * 60
	Hour   = Minute * 60
	Day    = Hour * 24
	Week   = Day * 7
	Month  = Day * 30
	Year   = Day * 365

	TimeLayout = time.RFC3339Nano
)

Common durations that is . There are some definitions for units of Day and larger .

Variables

This section is empty.

Functions

func CombineErrors

func CombineErrors(errs []error, formatErrMsg FormatErrMsgFunc) error

CombineErrors is a function which used by Inspect to merge multiple errors into one error.

func Contains

func Contains(input []interface{}, value interface{}) (bool, error)

Contains check if a interface in a interface slice.

func DeDuplicate

func DeDuplicate(input []string) []string

DeDuplicate make a slice with no duplicated elements.

func FormatSize

func FormatSize(size int64) string

FormatSize format image size to B/KB/MB/GB

func FormatTimeInterval

func FormatTimeInterval(input int64) (formattedTime string, err error)

FormatTimeInterval is used to show the time interval from input time to now.

func If

func If(cond bool, v1, v2 interface{}) interface{}

If implements ternary operator. if cond is true return v1, or return v2 instead.

func IsMountpoint

func IsMountpoint(dir string) bool

IsMountpoint is used to check the directory is mountpoint or not.

func IsProcessAlive

func IsProcessAlive(pid int) bool

IsProcessAlive returns true if process with a given pid is running.

func KillProcess

func KillProcess(pid int)

KillProcess force-stops a process.

func MakeFSVolume

func MakeFSVolume(fscmd []string, devicePath string, timeout time.Duration) error

MakeFSVolume is used to make file system on device with format type and options.

func Merge

func Merge(src, dest interface{}) error

Merge merge object from src to dest, dest object should be pointer, only accept struct type, notice: src will overwrite dest's data

func MountVolume

func MountVolume(mountCmd []string, devicePath, mountPath string, timeout time.Duration) error

MountVolume is used to mount device to directory with options.

func NewPidfile

func NewPidfile(path string) error

NewPidfile checks if pidfile exist, and saves daemon pid.

func ParseTimestamp

func ParseTimestamp(value string, defaultSec int64) (int64, int64, error)

ParseTimestamp returns seconds and nanoseconds.

  1. If the value is empty, it will return default second, the second arg.
  2. If the incoming nanosecond portion is longer or shorter than 9 digits, it will be converted into 9 digits nanoseconds.

func SetOOMScore

func SetOOMScore(pid, score int) error

SetOOMScore sets process's oom_score value The higher the value of oom_score of any process, the higher is its likelihood of getting killed by the OOM Killer in an out-of-memory situation.

func StringInSlice

func StringInSlice(input []string, str string) bool

StringInSlice checks if a string in the slice.

func TruncateID

func TruncateID(id string) string

TruncateID is used to transfer image ID from digest to short ID.

Types

type FormatErrMsgFunc

type FormatErrMsgFunc func(idx int, err error) (string, error)

FormatErrMsgFunc is a function which used by CombineErrors to format error message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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