uid

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

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

Go to latest
Published: Nov 1, 2017 License: MIT Imports: 9 Imported by: 2

README

uid

A package for generating unique identifiers, loosely based on MongoDB's ObjectId.

Identifiers are 12-bytes and roughly time sortable.

  • a 4-byte value representing the seconds since the Unix epoch,
  • a 3-byte machine identifier,
  • a 2-byte process id, and
  • a 3-byte counter, starting with a random value.

Documentation

Package documentation available on GoDoc: uid: github.com/billglover/uid

Benchmarks

goos: darwin
goarch: amd64
pkg: github.com/billglover/uid
BenchmarkUID-4          10000000               189 ns/op
BenchmarkUIDString-4    10000000               186 ns/op

Documentation

Overview

Package uid provides functions to generate roughly time ordered unique identifiers. The implementation is based on the MongoDB ObjectId specification. See https://docs.mongodb.com/manual/reference/method/ObjectId/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextID

func NextID() ([]byte, error)

NextID returns a new uid without requiring an instance of the generator. This is functionally identical, but incurs the additional overhead of setting up the generator on each request.

func NextStringID

func NextStringID() (string, error)

NextStringID returns a new uid without requiring an instance of the generator. This is functionally identical, but incurs the additional overhead of setting up the generator on each request.

Types

type Gen

type Gen struct {
	// contains filtered or unexported fields
}

Gen represents a uid generator

func NewGenerator

func NewGenerator() *Gen

NewGenerator returns an instance of a UID generator. During initialisation it generates the machine and process identifiers.

func (*Gen) NextID

func (g *Gen) NextID() ([]byte, error)

NextID returns the next uid in the sequence or an error if a valid uid could not be generated.

func (*Gen) NextStringID

func (g *Gen) NextStringID() (string, error)

NextStringID returns the next uid in the sequence as a hexadecimal string or an error if a valid uid could not be generated.

Jump to

Keyboard shortcuts

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