utils

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: Apache-2.0 Imports: 26 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ENOTSUP = errors.New("not supported")
)
View Source
var NativeEndian binary.ByteOrder

Functions

func Alloc

func Alloc(size int) []byte

Alloc returns size bytes memory from Go heap.

func AllocMemory added in v0.16.1

func AllocMemory() int64

AllocMemory returns the allocated memory

func Clock added in v0.12.0

func Clock() time.Duration

func DisableLogColor added in v1.0.0

func DisableLogColor()

func Exists

func Exists(path string) bool

Exists checks if the file/folder in given path exists

func FindLocalIPs added in v1.1.0

func FindLocalIPs() ([]net.IP, error)

func FormatBytes added in v1.0.0

func FormatBytes(n uint64) string

func Free

func Free(b []byte)

Free returns memory to Go heap.

func GetDev added in v1.0.0

func GetDev(fpath string) int

func GetFileInode added in v0.11.0

func GetFileInode(path string) (uint64, error)

func GetKernelInfo added in v1.1.0

func GetKernelInfo() (string, error)

func GetKernelVersion added in v1.0.0

func GetKernelVersion() (major, minor int)

func GetLocalIp added in v1.0.0

func GetLocalIp(address string) (string, error)

GetLocalIp get the local ip used to access remote address.

func GetLogger

func GetLogger(name string) *logHandle

GetLogger returns a logger mapped to `name`

func GetSysInfo added in v1.1.0

func GetSysInfo() string

func GetUmask added in v1.1.0

func GetUmask() int

func GroupName added in v1.1.0

func GroupName(gid int) string

func GuessMimeType added in v1.0.0

func GuessMimeType(key string) string

func InitLoggers

func InitLoggers(logToSyslog bool)

func LookupGroup added in v1.1.0

func LookupGroup(name string) int

func LookupUser added in v1.1.0

func LookupUser(name string) int

func MemoryUsage added in v0.11.0

func MemoryUsage() (virt, rss uint64)

func Min

func Min(a, b int) int

Min returns min of 2 int

func MockProgress added in v1.0.0

func MockProgress() (*Progress, *Bar)

func Now added in v0.12.0

func Now() time.Time

func RemovePassword added in v1.0.0

func RemovePassword(uri string) string

func SetLogLevel

func SetLogLevel(lvl logrus.Level)

SetLogLevel sets Level to all the loggers in the map

func SetOutFile added in v0.13.0

func SetOutFile(name string)

func SetOutput added in v1.0.0

func SetOutput(w io.Writer)

func SleepWithJitter added in v1.0.0

func SleepWithJitter(d time.Duration)

func SplitDir added in v0.11.0

func SplitDir(d string) []string

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

func StringContains added in v1.0.0

func StringContains(s []string, e string) bool

func SupportANSIColor added in v1.0.1

func SupportANSIColor(fd uintptr) bool

func UserName added in v1.1.0

func UserName(uid int) string

func WithTimeout added in v1.0.0

func WithTimeout(f func() error, timeout time.Duration) error

Types

type Bar added in v1.0.0

type Bar struct {
	*mpb.Bar
	// contains filtered or unexported fields
}

func (*Bar) Done added in v1.0.0

func (b *Bar) Done()

func (*Bar) IncrTotal added in v1.0.0

func (b *Bar) IncrTotal(n int64)

func (*Bar) SetTotal added in v1.0.0

func (b *Bar) SetTotal(total int64)

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 with 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. It's required for the caller to hold L.

func (*Cond) Signal

func (c *Cond) Signal()

Signal wakes up a waiter. It's required for the caller to hold L.

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 DoubleSpinner added in v1.0.0

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

func (*DoubleSpinner) Current added in v1.0.0

func (s *DoubleSpinner) Current() (int64, int64)

func (*DoubleSpinner) Done added in v1.0.0

func (s *DoubleSpinner) Done()

func (*DoubleSpinner) IncrInt64 added in v1.0.0

func (s *DoubleSpinner) IncrInt64(size int64)

func (*DoubleSpinner) SetCurrent added in v1.0.0

func (s *DoubleSpinner) SetCurrent(count, bytes int64)

type Progress added in v1.0.0

type Progress struct {
	*mpb.Progress
	Quiet bool
	// contains filtered or unexported fields
}

func NewProgress added in v1.0.0

func NewProgress(quiet bool) *Progress

func (*Progress) AddByteSpinner added in v1.0.0

func (p *Progress) AddByteSpinner(name string) *Bar

func (*Progress) AddCountBar added in v1.0.0

func (p *Progress) AddCountBar(name string, total int64) *Bar

func (*Progress) AddCountSpinner added in v1.0.0

func (p *Progress) AddCountSpinner(name string) *Bar

func (*Progress) AddDoubleSpinner added in v1.0.0

func (p *Progress) AddDoubleSpinner(name string) *DoubleSpinner

func (*Progress) AddDoubleSpinnerTwo added in v1.1.0

func (p *Progress) AddDoubleSpinnerTwo(countName, sizeName string) *DoubleSpinner

func (*Progress) AddIoSpeedBar added in v1.0.0

func (p *Progress) AddIoSpeedBar(name string, total int64) *Bar

func (*Progress) Done added in v1.0.0

func (p *Progress) Done()

type Rusage added in v0.11.0

type Rusage struct {
	syscall.Rusage
}

func GetRusage added in v0.11.0

func GetRusage() *Rusage

GetRusage returns CPU usage of current process.

func (*Rusage) GetStime added in v0.11.0

func (ru *Rusage) GetStime() float64

GetStime returns the system time in seconds.

func (*Rusage) GetUtime added in v0.11.0

func (ru *Rusage) GetUtime() float64

GetUtime returns the user time in seconds.

type SyslogHook

type SyslogHook struct {
	*logrus_syslog.SyslogHook
	// contains filtered or unexported fields
}

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