bigflake

package
v0.0.0-...-d627679 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 9 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidWorkerId  error = errors.New("Invalid worker ID - worker ID out of range")
	ErrOverflow         error = errors.New("Timestamp overflow (past end of lifespan) - unable to generate any more IDs")
	ErrSequenceOverflow error = errors.New("Sequence overflow (too many IDs generated) - unable to generate IDs for 1 millisecond")
)

Functions

func MintId

func MintId(timestamp, workerid, sequence int64) *big.Int

MintId mints new 128bit IDs from the timestamp, worker ID and sequence, this should only be used directly for testing

func ParseId

func ParseId(id *big.Int) (timestamp, workerid, sequence int64)

Types

type Bigflake

type Bigflake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(workerId uint64) (*Bigflake, error)

New initialises a Bigflake minter, with a default configuration This can be configured using Options

func (*Bigflake) Mint

func (bf *Bigflake) Mint() (*BigflakeId, error)

Mint a new 128bit ID based on the current time, worker id and sequence

type BigflakeId

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

BigflakeId represents a globally unique ID

func NewId

func NewId(id *big.Int) *BigflakeId

NewId creates a BigflakeId from a big.Int

func ParseUuid

func ParseUuid(s string) (bf *BigflakeId, err error)

ParseUuid into a BigflakeId

func (*BigflakeId) Base62

func (bf *BigflakeId) Base62() string

Base62 returns a base62 encoded version

func (*BigflakeId) Base62WithPadding

func (bf *BigflakeId) Base62WithPadding(minlen int) string

Base62WithPadding returns a base62 encoded id with left padding

func (*BigflakeId) BinaryString

func (bf *BigflakeId) BinaryString() string

BinaryString returns a padded 128bit binary number formatted as a string

func (*BigflakeId) Raw

func (bf *BigflakeId) Raw() *big.Int

Raw returns a raw 128bit integer

func (*BigflakeId) String

func (bf *BigflakeId) String() string

String returns the raw id as a string

func (*BigflakeId) Uuid

func (bf *BigflakeId) Uuid() string

Uuid returns the id encoded in UUID format

Jump to

Keyboard shortcuts

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