snowflake

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package snowflake provides a very simple Twitter snowflake generator and parser. https://github.com/bwmarrin/snowflake

Index

Constants

This section is empty.

Variables

View Source
var (
	// Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds
	// You may customize this to set a different epoch for your application.
	Epoch = int64(1288834974657)

	// NodeBits Number of bits to use for Node
	// Remember, you have a total 22 bits to share between Node/Step
	NodeBits uint8 = 8

	// StepBits Number of bits to use for Step
	// Remember, you have a total 22 bits to share between Node/Step
	StepBits uint8 = 14
)

Functions

This section is empty.

Types

type ID

type ID int64

An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.

func (ID) Int64

func (f ID) Int64() int64

Int64 returns an int64 of the snowflake ID

func (ID) Node

func (f ID) Node() int64

Node returns an int64 of the snowflake ID node number

func (ID) Step

func (f ID) Step() int64

Step returns an int64 of the snowflake step (or sequence) number

func (ID) String

func (f ID) String() string

String returns a string of the snowflake ID

func (ID) Time

func (f ID) Time() int64

Time returns an int64 unix timestamp of the snowflake ID time

type Node

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

A Node struct holds the basic information needed for a snowflake generator node

func NewNode

func NewNode(node uint8) (*Node, error)

NewNode returns a new snowflake node that can be used to generate snowflake

func (*Node) Generate

func (n *Node) Generate() ID

Generate creates and returns a unique snowflake ID

func (*Node) GenerateWithInt64 added in v1.0.11

func (n *Node) GenerateWithInt64() int64

GenerateWithInt64 creates and returns a unique snowflake ID

func (*Node) ID added in v1.1.5

func (n *Node) ID() int64

ID creates and returns a unique snowflake ID

Jump to

Keyboard shortcuts

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