Skip to content

jefurry/goid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Globally Unique ID Generator

godoc license Build Status Coverage

Package goid is a globally unique id generator library, ready to be used safely directly in your server code.

goid is using 128bit and hashids algorithm to generate globally unique ids to make it shorter when transported as a string: https://github.com/speps/go-hashids

  • 8-byte value representing the milliseconds since the Unix epoch,
  • 4-byte counter, starting with a random value,
  • 6-bit server room id,
  • 8-bit cluster id,
  • 9-bit machine id,
  • 3-bit work id, and
  • 6-bit op id.

The string representation is using hashids to generates (28bytes).

Features:

  • Size: 16 bytes (128 bits)
  • Lock-free (i.e.: unlike UUIDv1 and v2)

Install

go get -u github.com/speps/go-hashids
go get -u github.com/jefurry/goid

Usage

import (
    "github.com/jefurry/goid"
)

id := goid.New()

s, _ := id.Encode(0, 0, 0, 0, 0)
err := id.FromString(s)

func init() {
    goid.SeedMathRand()
}

Get goid embedded info:

id.Timestamp()
id.Counter()
id.ServerRoomID()
id.ClusterID()
id.MachineID()
id.WorkID()
id.OpID()

Licenses

All source code is licensed under the BSD License.

About

goid is a globally unique id generator

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages