common

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 20 Imported by: 1

README

Common go library.

Documentation

Index

Constants

View Source
const (
	ANSIReset      = "\x1b[0m"
	ANSIBright     = "\x1b[1m"
	ANSIDim        = "\x1b[2m"
	ANSIUnderscore = "\x1b[4m"
	ANSIBlink      = "\x1b[5m"
	ANSIReverse    = "\x1b[7m"
	ANSIHidden     = "\x1b[8m"

	ANSIFgBlack   = "\x1b[30m"
	ANSIFgRed     = "\x1b[31m"
	ANSIFgGreen   = "\x1b[32m"
	ANSIFgYellow  = "\x1b[33m"
	ANSIFgBlue    = "\x1b[34m"
	ANSIFgMagenta = "\x1b[35m"
	ANSIFgCyan    = "\x1b[36m"
	ANSIFgWhite   = "\x1b[37m"

	ANSIBgBlack   = "\x1b[40m"
	ANSIBgRed     = "\x1b[41m"
	ANSIBgGreen   = "\x1b[42m"
	ANSIBgYellow  = "\x1b[43m"
	ANSIBgBlue    = "\x1b[44m"
	ANSIBgMagenta = "\x1b[45m"
	ANSIBgCyan    = "\x1b[46m"
	ANSIBgWhite   = "\x1b[47m"
)

Variables

View Source
var (
	Zero256 = Word256{0}
	One256  = Word256{1}
)
View Source
var Fmt = fmt.Sprintf
View Source
var (
	GoPath = os.Getenv("GOPATH")
)

Functions

func Arr

func Arr(items ...interface{}) []interface{}

func Black

func Black(args ...interface{}) string

func Blue

func Blue(args ...interface{}) string

func Connect

func Connect(protoAddr string) (net.Conn, error)

func Cyan

func Cyan(args ...interface{}) string

func EnsureDir

func EnsureDir(dir string, mode os.FileMode) error

func Exit

func Exit(s string)

func ExpUint64

func ExpUint64(a, b uint64) uint64

func FileExists

func FileExists(filePath string) bool

func Fingerprint

func Fingerprint(slice []byte) []byte

func GetInt64BE

func GetInt64BE(src []byte) int64

func GetInt64LE

func GetInt64LE(src []byte) int64

func GetUint64BE

func GetUint64BE(src []byte) uint64

func GetUint64LE

func GetUint64LE(src []byte) uint64

func Green

func Green(args ...interface{}) string

func Int64FromWord256 added in v1.1.0

func Int64FromWord256(word Word256) int64

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

func IsZeros

func IsZeros(slice []byte) bool

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

func LeftPadString

func LeftPadString(s string, totalLength int) string

func Magenta

func Magenta(args ...interface{}) string

func MaxInt

func MaxInt(a, b int) int

func MaxInt16

func MaxInt16(a, b int16) int16

func MaxInt32

func MaxInt32(a, b int32) int32

func MaxInt64

func MaxInt64(a, b int64) int64

func MaxInt8

func MaxInt8(a, b int8) int8

func MaxUint

func MaxUint(a, b uint) uint

func MaxUint16

func MaxUint16(a, b uint16) uint16

func MaxUint32

func MaxUint32(a, b uint32) uint32

func MaxUint64

func MaxUint64(a, b uint64) uint64

func MaxUint8

func MaxUint8(a, b uint8) uint8

func MinInt

func MinInt(a, b int) int

func MinInt16

func MinInt16(a, b int16) int16

func MinInt32

func MinInt32(a, b int32) int32

func MinInt64

func MinInt64(a, b int64) int64

func MinInt8

func MinInt8(a, b int8) int8

func MinUint

func MinUint(a, b uint) uint

func MinUint16

func MinUint16(a, b uint16) uint16

func MinUint32

func MinUint32(a, b uint32) uint32

func MinUint64

func MinUint64(a, b uint64) uint64

func MinUint8

func MinUint8(a, b uint8) uint8

func MustReadFile

func MustReadFile(filePath string) []byte

func MustWriteFile

func MustWriteFile(filePath string, contents []byte, mode os.FileMode)

func PanicConsensus

func PanicConsensus(v interface{})

func PanicCrisis

func PanicCrisis(v interface{})

func PanicQ

func PanicQ(v interface{})

func PanicSanity

func PanicSanity(v interface{})

func Parallel

func Parallel(tasks ...func())

func Prompt

func Prompt(prompt string, defaultValue string) (string, error)

func PutInt64BE

func PutInt64BE(dest []byte, i int64)

func PutInt64LE

func PutInt64LE(dest []byte, i int64)

func PutUint64BE

func PutUint64BE(dest []byte, i uint64)

func PutUint64LE

func PutUint64LE(dest []byte, i uint64)

func RandBytes

func RandBytes(n int) []byte

func RandFloat32

func RandFloat32() float32

func RandInt

func RandInt() int

func RandInt16

func RandInt16() int16

func RandInt32

func RandInt32() int32

func RandInt64

func RandInt64() int64

func RandStr

func RandStr(length int) string

func RandTime

func RandTime() time.Time

func RandUint

func RandUint() uint

func RandUint16

func RandUint16() uint16

func RandUint16Exp

func RandUint16Exp() uint16

func RandUint32

func RandUint32() uint32

func RandUint32Exp

func RandUint32Exp() uint32

func RandUint64

func RandUint64() uint64

func RandUint64Exp

func RandUint64Exp() uint64

func ReadFile

func ReadFile(filePath string) ([]byte, error)

func Red

func Red(args ...interface{}) string

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

func RightPadString

func RightPadString(s string, totalLength int) string

func SearchUint64s

func SearchUint64s(a []uint64, x uint64) int

func Tempdir

func Tempdir(prefix string) (*os.File, string)

func Tempfile

func Tempfile(prefix string) (*os.File, string)

func TrapSignal

func TrapSignal(cb func())

func TrimmedString

func TrimmedString(b []byte) string

func Tuple256Split added in v1.1.0

func Tuple256Split(t Tuple256) (Word256, Word256)

func Uint64FromWord256 added in v1.1.0

func Uint64FromWord256(word Word256) uint64

func White

func White(args ...interface{}) string

func WriteFile

func WriteFile(filePath string, contents []byte, mode os.FileMode) error

func WriteFileAtomic

func WriteFileAtomic(filename string, data []byte, perm os.FileMode) error

func Yellow

func Yellow(args ...interface{}) string

Types

type BaseService

type BaseService struct {
	Quit chan struct{}
	// contains filtered or unexported fields
}

func NewBaseService

func NewBaseService(logger log.Logger, name string, impl Service) *BaseService

func (*BaseService) IsRunning

func (bs *BaseService) IsRunning() bool

func (*BaseService) OnReset

func (bs *BaseService) OnReset() error

func (*BaseService) OnStart

func (bs *BaseService) OnStart() error

func (*BaseService) OnStop

func (bs *BaseService) OnStop()

func (*BaseService) Reset

func (bs *BaseService) Reset() (bool, error)

func (*BaseService) Start

func (bs *BaseService) Start() (bool, error)

func (*BaseService) Stop

func (bs *BaseService) Stop() bool

func (*BaseService) String

func (bs *BaseService) String() string

func (*BaseService) Wait

func (bs *BaseService) Wait()

type BitArray

type BitArray struct {
	Bits  uint64   `json:"bits"`
	Elems []uint64 `json:"elems"`
	// contains filtered or unexported fields
}

func NewBitArray

func NewBitArray(bits uint64) *BitArray

func (*BitArray) And

func (bA *BitArray) And(o *BitArray) *BitArray

func (*BitArray) Bytes

func (bA *BitArray) Bytes() []byte

func (*BitArray) Copy

func (bA *BitArray) Copy() *BitArray

func (*BitArray) GetIndex

func (bA *BitArray) GetIndex(i uint64) bool

func (*BitArray) IsEmpty

func (bA *BitArray) IsEmpty() bool

func (*BitArray) IsFull

func (bA *BitArray) IsFull() bool

func (*BitArray) Not

func (bA *BitArray) Not() *BitArray

func (*BitArray) NumBitsSet

func (bA *BitArray) NumBitsSet() int

func (*BitArray) Or

func (bA *BitArray) Or(o *BitArray) *BitArray

func (*BitArray) PickRandom

func (bA *BitArray) PickRandom() (uint64, bool)

func (*BitArray) SetIndex

func (bA *BitArray) SetIndex(i uint64, v bool) bool

func (*BitArray) Size

func (bA *BitArray) Size() uint64

func (*BitArray) String

func (bA *BitArray) String() string

func (*BitArray) StringIndented

func (bA *BitArray) StringIndented(indent string) string

func (*BitArray) Sub

func (bA *BitArray) Sub(o *BitArray) *BitArray

func (*BitArray) Update

func (bA *BitArray) Update(o *BitArray)

type BufferCloser

type BufferCloser struct {
	bytes.Buffer
	Closed bool
}

func NewBufferCloser

func NewBufferCloser(buf []byte) *BufferCloser

func (*BufferCloser) Close

func (bc *BufferCloser) Close() error

func (*BufferCloser) Write

func (bc *BufferCloser) Write(p []byte) (n int, err error)

func (*BufferCloser) WriteByte

func (bc *BufferCloser) WriteByte(c byte) error

func (*BufferCloser) WriteRune

func (bc *BufferCloser) WriteRune(r rune) (n int, err error)

func (*BufferCloser) WriteString

func (bc *BufferCloser) WriteString(s string) (n int, err error)

type CMap

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

func NewCMap

func NewCMap() *CMap

func (*CMap) Clear

func (cm *CMap) Clear()

func (*CMap) Delete

func (cm *CMap) Delete(key string)

func (*CMap) Get

func (cm *CMap) Get(key string) interface{}

func (*CMap) Has

func (cm *CMap) Has(key string) bool

func (*CMap) Set

func (cm *CMap) Set(key string, value interface{})

func (*CMap) Size

func (cm *CMap) Size() int

func (*CMap) Values

func (cm *CMap) Values() []interface{}

type Comparable

type Comparable interface {
	Less(o interface{}) bool
}

type Heap

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

func NewHeap

func NewHeap() *Heap

func (*Heap) Len

func (h *Heap) Len() int64

func (*Heap) Peek

func (h *Heap) Peek() interface{}

func (*Heap) Pop

func (h *Heap) Pop() interface{}

func (*Heap) Push

func (h *Heap) Push(value interface{}, priority Comparable)

func (*Heap) Update

func (h *Heap) Update(value interface{}, priority Comparable)

type PrefixedReader

type PrefixedReader struct {
	Prefix []byte
	// contains filtered or unexported fields
}

func NewPrefixedReader

func NewPrefixedReader(prefix []byte, reader io.Reader) *PrefixedReader

func (*PrefixedReader) Read

func (pr *PrefixedReader) Read(p []byte) (n int, err error)

type QuitService

type QuitService struct {
	BaseService
}

func NewQuitService

func NewQuitService(logger log.Logger, name string, impl Service) *QuitService

type RepeatTimer

type RepeatTimer struct {
	Ch chan time.Time
	// contains filtered or unexported fields
}

func NewRepeatTimer

func NewRepeatTimer(name string, dur time.Duration) *RepeatTimer

func (*RepeatTimer) Reset

func (t *RepeatTimer) Reset()

func (*RepeatTimer) Stop

func (t *RepeatTimer) Stop() bool

type Service

type Service interface {
	Start() (bool, error)
	OnStart() error

	Stop() bool
	OnStop()

	Reset() (bool, error)
	OnReset() error

	IsRunning() bool

	String() string
}

type StackError

type StackError struct {
	Err   interface{}
	Stack []byte
}

func (StackError) Error

func (se StackError) Error() string

func (StackError) String

func (se StackError) String() string

type ThrottleTimer

type ThrottleTimer struct {
	Name string
	Ch   chan struct{}
	// contains filtered or unexported fields
}

func NewThrottleTimer

func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer

func (*ThrottleTimer) Set

func (t *ThrottleTimer) Set()

func (*ThrottleTimer) Stop

func (t *ThrottleTimer) Stop() bool

func (*ThrottleTimer) Unset

func (t *ThrottleTimer) Unset()

type Tuple256 added in v1.1.0

type Tuple256 struct {
	First  Word256
	Second Word256
}

func (Tuple256) Compare added in v1.1.0

func (tuple Tuple256) Compare(other Tuple256) int

type Tuple256Slice added in v1.1.0

type Tuple256Slice []Tuple256

func (Tuple256Slice) Len added in v1.1.0

func (p Tuple256Slice) Len() int

func (Tuple256Slice) Less added in v1.1.0

func (p Tuple256Slice) Less(i, j int) bool

func (Tuple256Slice) Sort added in v1.1.0

func (p Tuple256Slice) Sort()

func (Tuple256Slice) Swap added in v1.1.0

func (p Tuple256Slice) Swap(i, j int)

type Uint64Slice

type Uint64Slice []uint64

func (Uint64Slice) Len

func (p Uint64Slice) Len() int

func (Uint64Slice) Less

func (p Uint64Slice) Less(i, j int) bool

func (Uint64Slice) Search

func (p Uint64Slice) Search(x uint64) int

func (Uint64Slice) Sort

func (p Uint64Slice) Sort()

func (Uint64Slice) Swap

func (p Uint64Slice) Swap(i, j int)

type Word256 added in v1.1.0

type Word256 [32]byte

func Int64ToWord256 added in v1.1.0

func Int64ToWord256(i int64) Word256

func LeftPadWord256 added in v1.1.0

func LeftPadWord256(bz []byte) (word Word256)

func RightPadWord256 added in v1.1.0

func RightPadWord256(bz []byte) (word Word256)

func Uint64ToWord256 added in v1.1.0

func Uint64ToWord256(i uint64) Word256

func (Word256) Bytes added in v1.1.0

func (w Word256) Bytes() []byte

func (Word256) Compare added in v1.1.0

func (w Word256) Compare(other Word256) int

func (Word256) Copy added in v1.1.0

func (w Word256) Copy() Word256

func (Word256) IsZero added in v1.1.0

func (w Word256) IsZero() bool

func (Word256) Postfix added in v1.1.0

func (w Word256) Postfix(n int) []byte

func (Word256) Prefix added in v1.1.0

func (w Word256) Prefix(n int) []byte

func (Word256) String added in v1.1.0

func (w Word256) String() string

func (Word256) TrimmedString added in v1.1.0

func (w Word256) TrimmedString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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