β¨
Generate Snowflake
Generate unique IDs. Inspired by Twitter's Snowflake system.
π¦
Installation
- Initialize your project (
go mod init example.com/example
) - Add package (
go get github.com/barbarbar338/snowflake
)
π€
Usage
package main
import "github.com/barbarbar338/snowflake"
func main() {
s := snowflake.Snowflake {
EPOCH: 1618606800, // your projects EPOCH
}
id := s.Generate() // Some unique snowflake ID (eg: 6782465263234318336)
}
π»
How It Works?
EPOCH: 1618606800
Snowflake: 6782465263234318336
Binary: 101111000100000001010000011100011001100100000100000000000000000
Timestamp: 1617065730866
WorkerID: 1
ProcessID: 0
Increment: 0
β------------------------------------------------------------------------β
β Binary β
β10111100010000000101000001110001100110010β β00001β β00000β β000000000000β
β Timestamp β β WID β β PID β β Increment β
π§¦
Contributing
Fell free to use GitHub's features.