Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidRuneArray(arr []rune) bool
- func NewByteRandom(randomSupplier RandomSupplier) *byteRandom
- func NewByteRandomWithSupplierFunc(randomSupplierFunc func(length int32) ([]byte, error)) *byteRandom
- func NewCryptoRandomSupplier() *cryptoRandomSupplier
- func NewIntRandom(intSupplier IntSupplier) *intRandom
- func NewIntRandomWithSupplierFunc(intSupplierFunc func() (int32, error)) *intRandom
- func NewMathRandomSupplier() *mathRandomSupplier
- func ToRuneArray(str string) []rune
- func TsidFactoryBuilder() *tsidFactoryBuilder
- type ByteSupplier
- type Clock
- type IntSupplier
- type Random
- type RandomSupplier
- type Tsid
- func (t *Tsid) GetRandom() int64
- func (t *Tsid) GetUnixMillis() int64
- func (t *Tsid) GetUnixMillisWithCustomEpoch(epoch int64) int64
- func (t *Tsid) IsValid(str string) bool
- func (t *Tsid) ToBytes() []byte
- func (t *Tsid) ToLowerCase() string
- func (t *Tsid) ToNumber() int64
- func (t *Tsid) ToString() string
- func (t *Tsid) ToStringWithAlphabets(alphabets []rune) string
- type TsidFactory
Constants ¶
const ( BYTE_SIZE = 8 INTEGER_SIZE_32 = 32 INTEGER_BYTES_32 = 4 )
Variables ¶
var ALPHABET_LOWERCASE []rune = []rune("0123456789abcdefghjkmnpqrstvwxyz")
var ALPHABET_UPPERCASE []rune = []rune("0123456789ABCDEFGHJKMNPQRSTVWXYZ")
var ALPHABET_VALUES []int64
Functions ¶
func IsValidRuneArray ¶
IsValidRuneArray validates the rune array.
func NewByteRandom ¶
func NewByteRandom(randomSupplier RandomSupplier) *byteRandom
func NewCryptoRandomSupplier ¶
func NewCryptoRandomSupplier() *cryptoRandomSupplier
func NewIntRandom ¶
func NewIntRandom(intSupplier IntSupplier) *intRandom
func NewMathRandomSupplier ¶
func NewMathRandomSupplier() *mathRandomSupplier
func ToRuneArray ¶
ToRuneArray converts the given string to rune array. It also performs validations on the rune array
func TsidFactoryBuilder ¶
func TsidFactoryBuilder() *tsidFactoryBuilder
TsidFactoryBuilder should be used to get instance of tsidFactory
Types ¶
type ByteSupplier ¶
type IntSupplier ¶
type RandomSupplier ¶
Suppliers
type Tsid ¶ added in v1.0.5
type Tsid struct {
// contains filtered or unexported fields
}
func FromNumber ¶
FromNumber returns pointer to tsid using the given number
func FromString ¶
FromString returns pointer to tsid by converting the given string to number. It validates the string before conversion.
func (*Tsid) GetRandom ¶ added in v1.0.5
GetRandom returns random component (node + counter) of the tsid
func (*Tsid) GetUnixMillis ¶ added in v1.0.5
GetUnixMillis returns time of creation in millis since 1970-01-01
func (*Tsid) GetUnixMillisWithCustomEpoch ¶ added in v1.0.5
GetUnixMillis returns time of creation in millis since 1970-01-01
func (*Tsid) ToBytes ¶ added in v1.0.5
ToBytes converts the number to bytes and returns the byte array
func (*Tsid) ToLowerCase ¶ added in v1.0.5
ToLowerCase converts the number to a canonical string in lower case. The output is 13 characters long and only contains characters from Crockford's base32 alphabets
func (*Tsid) ToString ¶ added in v1.0.5
ToString converts the number to a canonical string. The output is 13 characters long and only contains characters from Crockford's base32 alphabets
func (*Tsid) ToStringWithAlphabets ¶ added in v1.0.5
ToStringWithAlphabets converts the number to string using the given alphabets and returns it
type TsidFactory ¶ added in v1.0.5
type TsidFactory struct {
// contains filtered or unexported fields
}
tsidFactory is a singleton which should be used to generate random tsid
func (*TsidFactory) Generate ¶ added in v1.0.5
func (factory *TsidFactory) Generate() (*Tsid, error)
Generate will return a tsid with random number