snowflake/README.md

44 lines
1.4 KiB
Markdown
Raw Normal View History

2016-05-25 14:56:18 -05:00
# flake
2016-06-01 14:59:26 -05:00
====
[![GoDoc](https://godoc.org/github.com/bwmarrin/flake?status.svg)](https://godoc.org/github.com/bwmarrin/flake) [![Go report](http://goreportcard.com/badge/bwmarrin/flake)](http://goreportcard.com/report/bwmarrin/flake) [![Build Status](https://travis-ci.org/bwmarrin/flake.svg?branch=master)](https://travis-ci.org/bwmarrin/flake)
[![Discord Gophers](https://img.shields.io/badge/Discord%20Gophers-%23flake.svg)](https://discord.gg/0f1SbxBZjYoCtNPP)
2016-05-25 14:56:18 -05:00
2016-06-01 14:59:26 -05:00
flake is a Google Go (golang) package that provides a very simple twitter
snowflake generator.
2016-05-25 16:28:44 -05:00
2016-06-01 14:59:26 -05:00
====
2016-05-25 15:07:49 -05:00
2016-06-01 14:59:26 -05:00
flake is a [Go](https://golang.org/) package that provides a very simple twitter
snowflake ID generator along with several functions to convert an ID into
different formats.
2016-05-25 15:07:49 -05:00
2016-06-01 14:59:26 -05:00
## Getting Started
### Installing
This assumes you already have a working Go environment, if not please see
[this page](https://golang.org/doc/install) first.
```sh
go get github.com/bwmarrin/flake
2016-05-25 15:07:49 -05:00
```
2016-06-01 14:59:26 -05:00
### Usage
Import the package into your project.
```go
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.
```go
node, err := flake.NewNode(1)
id := node.Generate()
fmt.Printf("ID: %d, %s\n", id, id.String())
2016-05-25 15:07:49 -05:00
```