snowflake/README.md
2016-06-01 14:59:26 -05:00

1.4 KiB

flake

==== GoDoc Go report Build Status Discord Gophers

flake is a Google Go (golang) package that provides a very simple twitter snowflake generator.

====

flake is a Go package that provides a very simple twitter snowflake ID generator along with several functions to convert an ID into different formats.

Getting Started

Installing

This assumes you already have a working Go environment, if not please see this page first.

go get github.com/bwmarrin/flake

Usage

Import the package into your project.

import "github.com/bwmarrin/flake"

Construct a new flake Node that can be used to generate snowflake IDs then call the Generate method to get a unique ID. The only argument to the NewNode() method is a Node number. Each node you create must have it's own unique Node number. A node number can be any number from 0 to 1023.

node, err := flake.NewNode(1)
id := node.Generate()
fmt.Printf("ID: %d, %s\n", id, id.String())