Skip to content

Eodomius/idgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

idgen

A module for generate snowflakes ids

Installation

You can install idgen with following command:

go get github.com/Eodomius/idgen

Usage

Import the module:

import (
  "github.com/Eodomius/idgen"
)

Features

Generate snowflake id

You can generate new snowflake id with Generate function:

id := idgen.Generate()

Return : int64

Deconsruct snowflake id

You can deconstruct snowflake to get timestamp, machine id, worker id and sequence id with Deconstruct function:

values := idgen.Deconstruct(id)

Return : Snowflake

GetTimestamp

You can get timestamp from snowflake id with GetTimestamp function:

timestamp := idgen.GetTimestamp(id)

Get worker id

You can get worker id from snowflake id with GetWorkerId function:

workerId := idgen.GetWorkerId(id)

Return : int

Get machine id

You can get machine id from snowflake id with GetMachineId function:

machineId := idgen.GetMachineId(id)

Return : int

Get increment

You can get sequence id from snowflake id with GetIncrement function:

increment := idgen.GetIncrement(id)

Return : int

Typedef

Snowflake

type Snowflake struct {
  timestamp uint64
  workerID  uint64
  processID uint64
  increment uint64
}

Releases

No releases published

Packages

No packages published

Languages