tools

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: BSD-3-Clause Imports: 31 Imported by: 5

Documentation

Index

Constants

View Source
const (
	DIGITS        = "0123456789"
	ALPHANUMERICS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
)

Variables

View Source
var (
	ErrNoCmds = errors.New("pipe: there were no commands provided")
)
View Source
var (
	RegExPhone *regexp.Regexp
)

Functions

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 CertTemplate

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

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

func CreateCert

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

func GenerateSelfSignedCerts

func GenerateSelfSignedCerts(keyPath, certPath string)

func GetCertificate

func GetCertificate(keyPath, certPath string) tls.Certificate

func GetCountryCode

func GetCountryCode(phone string) string

func Int32ToStr

func Int32ToStr(x int32) string

func Int64ToStr

func Int64ToStr(x int64) string

func MustSha256

func MustSha256(in []byte) []byte

func MustSha512

func MustSha512(in, out []byte)

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 RandomInt

func RandomInt(n int) (x int)

func RandomInt64

func RandomInt64(n int64) (x int64)

RandomInt64 produces a pseudo-random 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)

RandUint64 produces a pseudo-random unsigned number

func SanitizePhone

func SanitizePhone(phoneNumber string, defaultRegion string) string

func SecureRandomInt63

func SecureRandomInt63(n int64) (x int64)

func SecureRandomUint64

func SecureRandomUint64() (x uint64)

func Sha256

func Sha256(in []byte) ([]byte, error)

Sha256 returns a 32bytes array which is sha256(in)

func Sha512

func Sha512(in, out []byte) error

Sha512 returns a 64bytes array which is sha512(in)

func StrToByte

func StrToByte(str string) []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 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 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 UInt32ToStr

func UInt32ToStr(x uint32) string

func UInt64ToStr

func UInt64ToStr(x uint64) string

Types

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

Jump to

Keyboard shortcuts

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