snowflake

package module
v0.0.0-...-a87dd84 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2017 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Snowflake

This package is based on the golang implementation of the snowflake algorithm used to generate a unique id

Usage:


conf := Config{1, 2, 0}
i := NewIdWorker(conf)
id := i.Generate()
log.Printf("id: %d \n", id)

machine := i.Machine(id)
log.Printf("machine: %d \n", machine)

datacenter := i.Datacenter(id)
log.Printf("datacenter: %d \n", datacenter)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Machine    int64
	Datacenter int64
	Epoch      int64
}

type IdWorker

type IdWorker interface {
	Generate() int64
	Millisecond(int64, int64) int64
	Machine(int64) int64
	Datacenter(int64) int64
}

func NewIdWorker

func NewIdWorker(c Config) IdWorker

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL