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 ¶
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 ¶
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 ¶
NextID returns the next uid in the sequence or an error if a valid uid could not be generated.
func (*Gen) NextStringID ¶
NextStringID returns the next uid in the sequence as a hexadecimal string or an error if a valid uid could not be generated.