Skip to content

Fast ID generator based on timestamp, sequence number and worker id.

License

Notifications You must be signed in to change notification settings

cristalhq/fastid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastid

build-img pkg-img reportcard-img coverage-img

Fast ID generator based on timestamp, sequence number and worker id.

Rationale

Generating IDs quickly is a common task. Making this quickly is a nice thing to have.

Features

  • Simple.
  • Thread-safe.
  • Time based.
  • Dependency-free.

Install

go get github.com/cristalhq/fastid

Example

gen, err := NewGenerator(100, 200)

id := gen.Next()

ts, seq, w := id.Parts()

ts = id.Timestamp()
seq = id.Sequence()
w = id.WorkerID()

Documentation

See these docs.

License

MIT License.