🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

github.com/xiaojunjun-li/snowflake

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/xiaojunjun-li/snowflake

v0.0.0-20220816053432-5dc2e1f943b2
Source
Go
Version published
Created
Source

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/zhenorzz/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/zhenorzz/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)
}

FAQs

Package last updated on 16 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts