Skip to content

BS2911/snowflake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

snowflake

snowflake uuid

Getting Started

Installing

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

go get github.com/BS2911/snowflake

Usage

Import the package into your project then construct a new snowflake WorkID using a unique node number. The default settings permit a node number range from 0 to 1023. If you have set a custom NodeBits value, you will need to calculate what your node number range will be. With the node object call the Generate() method to generate and return a unique snowflake ID.

Keep in mind that each worker you create must have a unique node number, even across multiple servers. If you do not keep node numbers unique the generator cannot guarantee unique IDs across all nodes.

Example Program:

package main

import (
	"fmt"

	"github.com/BS2911/snowflake"
)

func main() {

    // Create a new Node with a Node number of 1
    sf, err := snowflake.New(1)
    if err != nil {
        panic(err)
    }

    // Generate a snowflake ID.
    uuid := sf.Generate()

    // Print
    fmt.Println(uuid)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages