snowflake

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: 6 Imported by: 5

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

This section is empty.

Types

type Snowflake

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

func New

func New(workerId uint32) (*Snowflake, error)

New creates a new instance of a snowflake compatible ID minter the worker ID must be unique otherwise ID collisions are likely to occur

func (*Snowflake) Mint

func (sf *Snowflake) Mint() (string, error)

func (*Snowflake) MintID

func (sf *Snowflake) MintID() (uint64, error)

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

Jump to

Keyboard shortcuts

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