Skip to content

korzha/go-flake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 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/nordligulv/go-flake

Example

package main

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

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

	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

  • Go 100.0%