Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.
/ go-flake Public archive

go-flake generates unique identifiers that are roughly sortable by time.

License

Notifications You must be signed in to change notification settings

davidnarayan/go-flake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-flake

go-flake generates unique identifiers that are roughly sortable by time.

Flake can run on a cluster of machines and still generate unique IDs without requiring worker coordination.

A Flake ID is a 64-bit integer will the following components:

  • 41 bits is the timestamp with millisecond precision
  • 10 bits is the host id (uses IP modulo 2^10)
  • 13 bits is an auto-incrementing sequence for ID requests within the same millisecond

Installation

go get github.com/davidnarayan/go-flake

Example

package main

import (
	"log"
	"github.com/davidnarayan/go-flake"
)

func main() {
	f, err := flake.New()

	if err != nil {
		log.Fatal(err)
	}

	id := f.NextId()
	fmt.Println(id)
	fmt.Println(id.String())
}

Credit

This work is based on code and concepts from the following:

About

go-flake generates unique identifiers that are roughly sortable by time.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages