utils

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: AGPL-3.0 Imports: 22 Imported by: 34

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alloc

func Alloc(size int) []byte

Alloc returns size bytes memory from Go heap.

func AllocMemory

func AllocMemory() int64

AllocMemory returns the allocated memory

func Clock

func Clock() time.Duration

func CopyFile added in v0.9.0

func CopyFile(dst, src string) error

CopyFile copies file in src path to dst path

func Exists

func Exists(path string) bool

Exists checks if the file/folder in given path exists

func Free

func Free(b []byte)

Free returns memory to Go heap.

func GetFileInode

func GetFileInode(path string) (uint64, error)

func GetLogger

func GetLogger(name string) *logHandle

GetLogger returns a logger mapped to `name`

func GetStdLogger added in v0.9.0

func GetStdLogger(l *logHandle, lvl logrus.Level) *glog.Logger

GetStdLogger returns standard golang logger

func InitLoggers

func InitLoggers(logToSyslog bool)

func MemoryUsage

func MemoryUsage() (virt, rss uint64)

func Min

func Min(a, b int) int

Min returns min of 2 int

func NewDynProgressBar added in v0.16.1

func NewDynProgressBar(title string, quiet bool) (*mpb.Progress, *mpb.Bar)

NewDynProgressBar init a dynamic progress bar,the title will appears at the head of the progress bar

func NewProgressCounter added in v0.16.1

func NewProgressCounter(title string) (*mpb.Progress, *mpb.Bar)

NewProgressCounter init a progress counter

func NewSpinner added in v0.16.1

func NewSpinner() mpb.BarFiller

func Now

func Now() time.Time

func SetLogLevel

func SetLogLevel(lvl logrus.Level)

SetLogLevel sets Level to all the loggers in the map

func SetOutFile

func SetOutFile(name string)

func SplitDir

func SplitDir(d string) []string

SplitDir splits a path with default path list separator or comma.

Types

type Buffer

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

Buffer is a buffer to read/write integers.

func FromBuffer

func FromBuffer(buf []byte) *Buffer

FromBuffer utility to create *Buffer

func NewBuffer

func NewBuffer(sz uint32) *Buffer

NewBuffer returns a buffer with sz number of bytes.

func NewNativeBuffer

func NewNativeBuffer(buf []byte) *Buffer

NewNativeBuffer utility to create *Buffer of given size with nativeEndian

func ReadBuffer

func ReadBuffer(buf []byte) *Buffer

ReadBuffer utility to create *Buffer from slice of bytes

func (*Buffer) Buffer

func (b *Buffer) Buffer() []byte

Buffer returns

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the bytes

func (*Buffer) Get

func (b *Buffer) Get(l int) []byte

Get returns `l` bytes from offset

func (*Buffer) Get16

func (b *Buffer) Get16() uint16

Get16 returns uint16

func (*Buffer) Get32

func (b *Buffer) Get32() uint32

Get32 returns uint32

func (*Buffer) Get64

func (b *Buffer) Get64() uint64

Get64 returns uint64

func (*Buffer) Get8

func (b *Buffer) Get8() uint8

Get8 returns uint8

func (*Buffer) HasMore

func (b *Buffer) HasMore() bool

HasMore checks if offset is less than length

func (*Buffer) Left

func (b *Buffer) Left() int

Left returns number of bytes after offset

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns length of buffer

func (*Buffer) Put

func (b *Buffer) Put(v []byte)

Put appends slice of byte to Buffer

func (*Buffer) Put16

func (b *Buffer) Put16(v uint16)

Put16 appends uint16 to Buffer

func (*Buffer) Put32

func (b *Buffer) Put32(v uint32)

Put32 appends uint32 to Buffer

func (*Buffer) Put64

func (b *Buffer) Put64(v uint64)

Put64 appends uint64 to Buffer

func (*Buffer) Put8

func (b *Buffer) Put8(v uint8)

Put8 appends uint8 to Buffer

func (*Buffer) Seek

func (b *Buffer) Seek(p int)

Seek seeks or sets offset to `p`

func (*Buffer) SetBytes

func (b *Buffer) SetBytes(buf []byte)

SetBytes initilizes the Buffer with BigEndian ordering

type Cond

type Cond struct {
	L sync.Locker
	// contains filtered or unexported fields
}

Cond is similar to sync.Cond, but you can wait without a timeout.

func NewCond

func NewCond(lock sync.Locker) *Cond

NewCond creates a Cond.

func (*Cond) Broadcast

func (c *Cond) Broadcast()

Broadcast wake up all the waiters.

func (*Cond) Signal

func (c *Cond) Signal()

Signal wakes up a waiter.

func (*Cond) Wait added in v0.9.0

func (c *Cond) Wait()

Wait until Signal() or Broadcast() is called.

func (*Cond) WaitWithTimeout

func (c *Cond) WaitWithTimeout(d time.Duration) bool

WaitWithTimeout wait for a signal or a period of timeout eclipsed. returns true in case of timeout else false

type Rusage

type Rusage struct {
	syscall.Rusage
}

func GetRusage

func GetRusage() *Rusage

func (*Rusage) GetStime

func (ru *Rusage) GetStime() float64

func (*Rusage) GetUtime

func (ru *Rusage) GetUtime() float64

type SyslogHook

type SyslogHook struct {
	*logrus_syslog.SyslogHook
}

func (*SyslogHook) Fire

func (hook *SyslogHook) Fire(entry *logrus.Entry) error

Jump to

Keyboard shortcuts

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