ARCHIVED, SEE https://github.com/guoyk93/snowid
A concurrent-safe lock-free implementation of snowflake algorithm in Golang
go get -u github.com/guoyk93/snowflake
// assign a unique identifier
id, _ := strconv.ParseUint(os.Getenv("WORKER_ID"), 10, 64)
// create a instance
s := snowflake.New(snowflake.Options
Epoch: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC),
ID: id,
})
// get a id
s.NewID()
// stop and release all related resource
s.Stop()
Less than 1us/op
Guo Y.K., MIT License