Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nats-io/nuid
NATS Unique Identifiers
https://github.com/nats-io/nuid
Last synced: 15 days ago
JSON representation
NATS Unique Identifiers
- Host: GitHub
- URL: https://github.com/nats-io/nuid
- Owner: nats-io
- License: apache-2.0
- Created: 2016-02-23T21:36:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-01-06T22:03:53.000Z (almost 4 years ago)
- Last Synced: 2024-10-19T16:53:25.351Z (25 days ago)
- Language: Go
- Size: 22.5 KB
- Stars: 361
- Watchers: 36
- Forks: 44
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NUID
[![License Apache 2](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![ReportCard](http://goreportcard.com/badge/nats-io/nuid)](http://goreportcard.com/report/nats-io/nuid)
[![Build Status](https://travis-ci.com/nats-io/nuid.svg?branch=master)](https://travis-ci.com/nats-io/nuid)
[![Release](https://img.shields.io/badge/release-v1.0.1-1eb0fc.svg)](https://github.com/nats-io/nuid/releases/tag/v1.0.1)
[![GoDoc](http://godoc.org/github.com/nats-io/nuid?status.png)](http://godoc.org/github.com/nats-io/nuid)
[![Coverage Status](https://coveralls.io/repos/github/nats-io/nuid/badge.svg?branch=master)](https://coveralls.io/github/nats-io/nuid?branch=master)A highly performant unique identifier generator.
## Installation
Use the `go` command:
$ go get github.com/nats-io/nuid
## Basic Usage
```go// Utilize the global locked instance
nuid := nuid.Next()// Create an instance, these are not locked.
n := nuid.New()
nuid = n.Next()// Generate a new crypto/rand seeded prefix.
// Generally not needed, happens automatically.
n.RandomizePrefix()
```## Performance
NUID needs to be very fast to generate and be truly unique, all while being entropy pool friendly.
NUID uses 12 bytes of crypto generated data (entropy draining), and 10 bytes of pseudo-random
sequential data that increments with a pseudo-random increment.Total length of a NUID string is 22 bytes of base 62 ascii text, so 62^22 or
2707803647802660400290261537185326956544 possibilities.NUID can generate identifiers as fast as 60ns, or ~16 million per second. There is an associated
benchmark you can use to test performance on your own hardware.## License
Unless otherwise noted, the NATS source files are distributed
under the Apache Version 2.0 license found in the LICENSE file.