utils

package
v0.0.0-...-63245bf Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

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

func AllocMemory() int64

AllocMemory returns the allocated memory

func Clock

func Clock() time.Duration

func DisableLogColor

func DisableLogColor()

func Exists

func Exists(path string) bool

Exists checks if the file/folder in given path exists

func FindLocalIPs

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

func FormatBytes

func FormatBytes(n uint64) string

func Free

func Free(b []byte)

Free returns memory to Go heap.

func GetDev

func GetDev(fpath string) int

func GetFileInode

func GetFileInode(path string) (uint64, error)

func GetKernelInfo

func GetKernelInfo() (string, error)

func GetKernelVersion

func GetKernelVersion() (major, minor int)

func GetLocalIp

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

func GetSysInfo() string

func GetUmask

func GetUmask() int

func GroupName

func GroupName(gid int) string

func GuessMimeType

func GuessMimeType(key string) string

func InitLoggers

func InitLoggers(logToSyslog bool)

func LookupGroup

func LookupGroup(name string) int

func LookupUser

func LookupUser(name string) int

func Mbps

func Mbps(val int64) string

func MemoryUsage

func MemoryUsage() (virt, rss uint64)

func Min

func Min(a, b int) int

Min returns min of 2 int

func MockProgress

func MockProgress() (*Progress, *Bar)

func Now

func Now() time.Time

func ParseBytes

func ParseBytes(ctx *cli.Context, key string, unit byte) uint64

func ParseMbps

func ParseMbps(ctx *cli.Context, key string) int64

func RemovePassword

func RemovePassword(uri string) string

func SetLogID

func SetLogID(id string)

func SetLogLevel

func SetLogLevel(lvl logrus.Level)

SetLogLevel sets Level to all the loggers in the map

func SetOutFile

func SetOutFile(name string)

func SetOutput

func SetOutput(w io.Writer)

func SleepWithJitter

func SleepWithJitter(d time.Duration)

func SplitDir

func SplitDir(d string) []string

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

func StringContains

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

func SupportANSIColor

func SupportANSIColor(fd uintptr) bool

func UserName

func UserName(uid int) string

func WithTimeout

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

Types

type Bar

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

func (*Bar) Done

func (b *Bar) Done()

func (*Bar) GetTotal

func (b *Bar) GetTotal() int64

func (*Bar) IncrTotal

func (b *Bar) IncrTotal(n int64)

func (*Bar) SetTotal

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

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

func (*DoubleSpinner) Current

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

func (*DoubleSpinner) Done

func (s *DoubleSpinner) Done()

func (*DoubleSpinner) IncrInt64

func (s *DoubleSpinner) IncrInt64(size int64)

func (*DoubleSpinner) SetCurrent

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

type Progress

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

func NewProgress

func NewProgress(quiet bool) *Progress

func (*Progress) AddByteSpinner

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

func (*Progress) AddCountBar

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

func (*Progress) AddCountSpinner

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

func (*Progress) AddDoubleSpinner

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

func (*Progress) AddDoubleSpinnerTwo

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

func (*Progress) AddIoSpeedBar

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

func (*Progress) Done

func (p *Progress) Done()

type Rusage

type Rusage struct {
	syscall.Rusage
}

func GetRusage

func GetRusage() *Rusage

GetRusage returns CPU usage of current process.

func (*Rusage) GetStime

func (ru *Rusage) GetStime() float64

GetStime returns the system time in seconds.

func (*Rusage) GetUtime

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