tools

package
v0.16.25 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: BSD-3-Clause Imports: 32 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCommands = errors.New("pipe: there were no commands provided")
)

Functions

func AppendStrInt added in v0.6.28

func AppendStrInt(sb *strings.Builder, x int)

func AppendStrInt32 added in v0.6.28

func AppendStrInt32(sb *strings.Builder, x int32)

func AppendStrInt64 added in v0.6.28

func AppendStrInt64(sb *strings.Builder, x int64)

func AppendStrUInt added in v0.6.28

func AppendStrUInt(sb *strings.Builder, x uint)

func AppendStrUInt32 added in v0.6.28

func AppendStrUInt32(sb *strings.Builder, x uint32)

func AppendStrUInt64 added in v0.6.28

func AppendStrUInt64(sb *strings.Builder, x uint64)

func B2S added in v0.5.20

func B2S(bts []byte) string

B2S is alias for ByteToStr

func BoolPtr added in v0.14.20

func BoolPtr(in bool) (out *bool)

func ByteToStr

func ByteToStr(bts []byte) string

ByteToStr converts byte slice to a string without memory allocation. Note it may break if string and/or slice header will change in the future go versions.

func CPUTicks added in v0.0.35

func CPUTicks() int64

CPUTicks is a faster alternative to NanoTime to measure time duration.

func CertTemplate

func CertTemplate() (*x509.Certificate, error)

CertTemplate is a helper function to create a cert template with a serial number and other required fields

func ConstructorOf added in v0.9.0

func ConstructorOf(x interface{}) int64

func CreateCert

func CreateCert(
	template, parent *x509.Certificate,
	pub interface{}, parentPriv interface{},
) (cert *x509.Certificate, certPEM []byte, err error)

func DeleteItemFromSlice added in v0.6.28

func DeleteItemFromSlice(slice interface{}, index int)

DeleteItemFromSlice deletes item from slice. 'slice' MUST be a slice otherwise panics. 'index' MUST be valid otherwise panics.

func Duration added in v0.0.35

func Duration(t int64) time.Duration

func FastRand added in v0.0.35

func FastRand() uint32

FastRand is a fast thread local random function.

func GenerateSelfSignedCerts

func GenerateSelfSignedCerts(keyPath, certPath string)

func GetBytes added in v0.10.3

func GetBytes(v interface{}, defaultValue []byte) []byte

func GetCertificate

func GetCertificate(keyPath, certPath string) (*tls.Certificate, error)

func GetInt32 added in v0.10.3

func GetInt32(v interface{}, defaultValue int32) int32

func GetInt64 added in v0.10.3

func GetInt64(v interface{}, defaultValue int64) int64

func GetString added in v0.10.3

func GetString(v interface{}, defaultValue string) string

func GetUint32 added in v0.10.3

func GetUint32(v interface{}, defaultValue uint32) uint32

func GetUint64 added in v0.10.3

func GetUint64(v interface{}, defaultValue uint64) uint64

func Int32Ptr added in v0.14.8

func Int32Ptr(in int32) (out *int32)

func Int32ToStr

func Int32ToStr(x int32) string

func Int64Ptr added in v0.14.8

func Int64Ptr(in int64) (out *int64)

func Int64ToStr

func Int64ToStr(x int64) string

func IntPtr added in v0.14.8

func IntPtr(in int) (out *int)

func IntToStr added in v0.6.3

func IntToStr(x int) string

func MustSha256

func MustSha256(in, out []byte)

func MustSha512

func MustSha512(in, out []byte)

func NanoTime added in v0.0.35

func NanoTime() int64

NanoTime returns the current time in nanoseconds from a monotonic clock.

func NewPipeCommands

func NewPipeCommands(cmds ...*exec.Cmd) (*cmdPipe, error)

func RandomDigit

func RandomDigit(n int) string

RandomDigit generates a pseudo-random string with length 'n' which characters are only digits (0-9)

func RandomID

func RandomID(n int) string

RandomID generates a pseudo-random string with length 'n' which characters are alphanumerics.

func RandomIDs added in v0.11.3

func RandomIDs(n ...int) []string

func RandomInt

func RandomInt(n int) (x int)

func RandomInt32 added in v0.11.3

func RandomInt32(n int32) (x int32)

RandomInt32 produces a pseudo-random 31bit number, if n == 0 there will be no limit otherwise the output will be smaller than n

func RandomInt64

func RandomInt64(n int64) (x int64)

RandomInt64 produces a pseudo-random 63bit number, if n == 0 there will be no limit otherwise the output will be smaller than n

func RandomUint64

func RandomUint64(n uint64) (x uint64)

RandomUint64 produces a pseudo-random unsigned number

func S2B added in v0.5.20

func S2B(str string) []byte

S2B is alias for StrToByte

func SecureRandomInt63

func SecureRandomInt63(n int64) (x int64)

SecureRandomInt63 produces a secure pseudo-random 63bit number

func SecureRandomUint64

func SecureRandomUint64() (x uint64)

SecureRandomUint64 produces a secure pseudo-random 64bit number

func Sha256

func Sha256(in, out []byte) error

Sha256 appends a 32bytes array which is sha256(in) to out

func Sha512

func Sha512(in, out []byte) error

Sha512 appends a 64bytes array which is sha512(in) to out

func SliceBytesDiff added in v0.3.9

func SliceBytesDiff(a, b [][]byte, cb func([]byte))

SliceBytesDiff returns a - b and cb will be called on each found difference.

func SliceInt32Diff added in v0.3.9

func SliceInt32Diff(a, b []int32, cb func(int32))

SliceInt32Diff returns a - b and cb will be called on each found difference.

func SliceInt64Diff added in v0.3.9

func SliceInt64Diff(a, b []int64, cb func(int64))

SliceInt64Diff returns a - b and cb will be called on each found difference.

func SliceIntDiff added in v0.3.9

func SliceIntDiff(a, b []int, cb func(int))

SliceIntDiff returns a - b and cb will be called on each found difference.

func SliceStringDiff added in v0.3.9

func SliceStringDiff(a, b []string, cb func(string))

SliceStringDiff returns a - b and cb will be called on each found difference.

func SliceUint32Diff added in v0.3.9

func SliceUint32Diff(a, b []uint32, cb func(uint32))

SliceUint32Diff returns a - b and cb will be called on each found difference.

func SliceUint64Diff added in v0.3.9

func SliceUint64Diff(a, b []uint64, cb func(uint64))

SliceUint64Diff returns a - b and cb will be called on each found difference.

func SliceUintDiff added in v0.3.9

func SliceUintDiff(a, b []uint, cb func(uint))

SliceUintDiff returns a - b and cb will be called on each found difference.

func StrToByte

func StrToByte(str string) (b []byte)

StrToByte converts string to a byte slice without memory allocation. Note it may break if string and/or slice header will change in the future go versions.

func StrToFloat32 added in v0.10.3

func StrToFloat32(s string) float32

func StrToFloat64 added in v0.10.3

func StrToFloat64(s string) float64

func StrToInt added in v0.6.3

func StrToInt(s string) int

func StrToInt32

func StrToInt32(s string) int32

func StrToInt64

func StrToInt64(s string) int64

func StrToUInt32

func StrToUInt32(s string) uint32

func StrToUInt64

func StrToUInt64(s string) uint64

func StringPtr added in v0.14.8

func StringPtr(in string) (out *string)

func TimeUnix

func TimeUnix() int64

func ToCamel

func ToCamel(s string) string

ToCamel converts a string to CamelCase

func ToDelimited

func ToDelimited(s string, delimiter uint8) string

ToDelimited converts a string to delimited.snake.case (in this case `delimiter = '.'`)

func ToKebab

func ToKebab(s string) string

ToKebab converts a string to kebab-case

func ToLowerCamel

func ToLowerCamel(s string) string

ToLowerCamel converts a string to lowerCamelCase

func ToScreamingDelimited

func ToScreamingDelimited(s string, delimiter uint8, ignore uint8, screaming bool) string

ToScreamingDelimited converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `delimiter = '.'; screaming = true`) or delimited.snake.case (in this case `delimiter = '.'; screaming = false`)

func ToScreamingKebab

func ToScreamingKebab(s string) string

ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE

func ToScreamingSnake

func ToScreamingSnake(s string) string

ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE

func ToSnake

func ToSnake(s string) string

ToSnake converts a string to snake_case

func ToSnakeWithIgnore

func ToSnakeWithIgnore(s string, ignore uint8) string

func Try

func Try(attempts int, waitTime time.Duration, f RetryableFunc) (err error)

func TryFast added in v0.6.26

func TryFast(f RetryableFunc) error

func TrySlow added in v0.6.26

func TrySlow(f RetryableFunc) error

func TrySuperFast added in v0.6.26

func TrySuperFast(f RetryableFunc) error

func UInt32ToStr

func UInt32ToStr(x uint32) string

func UInt64ToStr

func UInt64ToStr(x uint64) string

func Uint32Ptr added in v0.14.8

func Uint32Ptr(in uint32) (out *uint32)

func Uint64Ptr added in v0.14.8

func Uint64Ptr(in uint64) (out *uint64)

func UintPtr added in v0.14.8

func UintPtr(in uint) (out *uint)

Types

type Allocator added in v0.7.1

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

func NewAllocator added in v0.7.1

func NewAllocator() *Allocator

func (*Allocator) FillWith added in v0.7.1

func (bk *Allocator) FillWith(v []byte) []byte

FillWith acquired a byte slice with the capacity of 'v' and append/copy v into it.

func (*Allocator) Gen added in v0.7.1

func (bk *Allocator) Gen(v ...interface{}) []byte

Gen acquired a byte slice fitted to hold all the v variables.

func (*Allocator) Marshal added in v0.7.1

func (bk *Allocator) Marshal(m proto.Message) []byte

Marshal acquires a byte slice fitted for message 'm'

func (*Allocator) ReleaseAll added in v0.7.1

func (bk *Allocator) ReleaseAll()

ReleaseAll releases all the byte slices.

type FlushEntry added in v0.1.4

type FlushEntry interface {
	Value() interface{}
	// contains filtered or unexported methods
}

func NewEntry added in v0.1.4

func NewEntry(v interface{}) FlushEntry

func NewEntryWithCallback added in v0.6.34

func NewEntryWithCallback(v interface{}, cb func()) FlushEntry

type FlusherFunc added in v0.1.4

type FlusherFunc func(targetID string, entries []FlushEntry)

type FlusherPool added in v0.3.2

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

func NewFlusherPool added in v0.1.4

func NewFlusherPool(maxWorkers, batchSize int32, f FlusherFunc) *FlusherPool

NewFlusherPool creates a pool of flusher funcs. By calling Enter or EnterAndWait you add the item into the flusher which identified by 'targetID'.

func NewFlusherPoolWithWaitTime added in v0.8.1

func NewFlusherPoolWithWaitTime(maxWorkers, batchSize int32, minWaitTime time.Duration, f FlusherFunc) *FlusherPool

func (*FlusherPool) Enter added in v0.3.2

func (fp *FlusherPool) Enter(targetID string, entry FlushEntry)

func (*FlusherPool) EnterAndWait added in v0.3.2

func (fp *FlusherPool) EnterAndWait(targetID string, entry FlushEntry)

type LinkedList

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

func NewLinkedList

func NewLinkedList() *LinkedList

func (*LinkedList) Append

func (ll *LinkedList) Append(data interface{})

func (*LinkedList) Get

func (ll *LinkedList) Get(index int32) (n *Node)

func (*LinkedList) Head

func (ll *LinkedList) Head() *Node

func (*LinkedList) PickHeadData

func (ll *LinkedList) PickHeadData() interface{}

func (*LinkedList) PickTailData

func (ll *LinkedList) PickTailData() interface{}

func (*LinkedList) Prepend

func (ll *LinkedList) Prepend(data interface{})

func (*LinkedList) RemoveAt

func (ll *LinkedList) RemoveAt(index int32)

func (*LinkedList) Reset

func (ll *LinkedList) Reset()

func (*LinkedList) Size

func (ll *LinkedList) Size() int32

func (*LinkedList) String

func (ll *LinkedList) String() string

func (*LinkedList) Tail

func (ll *LinkedList) Tail() *Node

type Node

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

func (Node) GetData

func (n Node) GetData() interface{}

type RetryableFunc

type RetryableFunc func() error

type SpinLock added in v0.1.4

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

SpinLock is a spinlock implementation.

A SpinLock must not be copied after first use. This SpinLock intended to be used to synchronize exceptionally short-lived operations.

func (*SpinLock) Lock added in v0.1.4

func (l *SpinLock) Lock()

Lock locks l. If the lock is already in use, the calling goroutine blocks until the locker is available.

func (*SpinLock) Unlock added in v0.1.4

func (l *SpinLock) Unlock()

Unlock unlocks l.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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