A module for generate snowflakes ids
You can install idgen with following command:
go get github.com/Eodomius/idgenImport the module:
import (
"github.com/Eodomius/idgen"
)You can generate new snowflake id with Generate function:
id := idgen.Generate()Return : int64
You can deconstruct snowflake to get timestamp, machine id, worker id and sequence id with Deconstruct function:
values := idgen.Deconstruct(id)Return : Snowflake
You can get timestamp from snowflake id with GetTimestamp function:
timestamp := idgen.GetTimestamp(id)You can get worker id from snowflake id with GetWorkerId function:
workerId := idgen.GetWorkerId(id)Return : int
You can get machine id from snowflake id with GetMachineId function:
machineId := idgen.GetMachineId(id)Return : int
You can get sequence id from snowflake id with GetIncrement function:
increment := idgen.GetIncrement(id)Return : int
type Snowflake struct {
timestamp uint64
workerID uint64
processID uint64
increment uint64
}