# README
snowflake
引用方法:
go get github.com/infoepoch/go-dev-common/utils/snowflake
使用方法
// Create a new Node with a Node number of 1
node, err := snowflake.NewNode(1)
if err != nil {
fmt.Println(err)
return
}
// Generate a snowflake ID.
id := node.Generate()
// Print out the ID in a few different ways.
fmt.Printf("Int64 ID: %d\n", id)
fmt.Printf("String ID: %s\n", id)
fmt.Printf("Base2 ID: %s\n", id.Base2())
fmt.Printf("Base64 ID: %s\n", id.Base64())
// Print out the ID's timestamp
fmt.Printf("ID Time : %d\n", id.Time())
// Print out the ID's node number
fmt.Printf("ID Node : %d\n", id.Node())
// Print out the ID's sequence number
fmt.Printf("ID Step : %d\n", id.Step())
// Generate and print, all in one.
fmt.Printf("ID : %d\n", node.Generate().Int64())
# Functions
NewNode returns a new snowflake node that can be used to generate snowflake IDs.
ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so becareful when doing any interoperation interop with other packages.
ParseBase58 parses a base58 []byte into a snowflake ID.
# Variables
Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC You may customize this to set a different epoch for your application.
ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte.
ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte.
NodeBits Number of bits to use for Node Remember, you have a total 22 bits to share between Node/Step.
StepBits Number of bits to use for Step Remember, you have a total 22 bits to share between Node/Step.
# Structs
A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.
A Node struct holds the basic information needed for a snowflake generator node.
# Type aliases
An ID is a custom type used for a snowflake ID.