Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

A concurrent-safe lock-free implementation of snowflake algorithm in Golang

License

Notifications You must be signed in to change notification settings

yankeguo-deprecated/snowflake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

snowflake

ARCHIVED, SEE https://github.com/guoyk93/snowid

BMC Donate Build Status

A concurrent-safe lock-free implementation of snowflake algorithm in Golang

Get

go get -u github.com/guoyk93/snowflake

Usage

// 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()

Performance

Less than 1us/op

Credits

Guo Y.K., MIT License