A tiny and fast Go unique string generator

Overview

Nano ID GoDoc

A tiny and fast Go unique string generator

  • Safe. It uses cryptographically strong random APIs and tests distribution of symbols.
  • Compact. It uses a larger alphabet than UUID (A-Za-z0-9_-). So ID size was reduced from 36 to 21 symbols.
id, err := nanoid.New() //> "i25_rX9zwDdDn7Sg-ZoaH"
if err != nil {
    log.Fatalln(err)
}

Installation

Once Go is installed, run the following command to get Nano ID.

go get github.com/aidarkhanov/nanoid/v2

Documentation

The package reference is located at pkg.go.dev/github.com/aidarkhanov/nanoid/v2.

Roadmap

  • The API of this package is frozen.
  • Release patches if necessary.

License

This package is provided under MIT/Expat license. See LICENSE.md file for details.

Thanks to

You might also like...
An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.

uuid The uuid package generates and inspects UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services. This package is based on the g

A distributed unique ID generator of using Sonyflake and encoded by Base58

Indigo About A distributed unique ID generator of using Sonyflake and encoded by Base58. ID max length is 11 characters by unsigned int64 max value. A

A distributed unique ID generator inspired by Twitter's Snowflake

Sonyflake is a distributed unique ID generator inspired by Twitter's Snowflake.

High performance unique number generator powered by Go

SEQSVR High performance unique number generator powered by Go 中文 README Features Distributed: Can be scaled horizontally High performance: Allocation

Compact, sortable and fast unique IDs with embedded metadata.
Compact, sortable and fast unique IDs with embedded metadata.

A spec for unique IDs in distributed systems based on the Snowflake design, i.e. a coordination-based ID variant. It aims to be friendly to both machi

Golang metrics for calculating string similarity and other string utility functions

strutil strutil provides string metrics for calculating string similarity as well as other string utility functions. Full documentation can be found a

Recursively searches a map[string]interface{} structure for another map[string]interface{} structure

msirecurse Recursively searches a map[string]interface{} structure for existence of a map[string]interface{} structure Motivation I wrote this package

Inflection is a string transformation library. It transforms strings from CamelCase to underscored string.

Inflection Inflection is a string transformation library. It transforms strings from CamelCase to underscored string. This is an implement of Inflecti

:guardsman: A teeny tiny and somewhat opinionated generator for your next golang project

A Yeoman Golang Generator We are very sorry Gophers, but other names for the generator where taken, so we choose go-lang. But we have gocreate as an a

Shikhandi: a tiny load generator for opentelemetry and heavily

shikhandi is a tiny load generator for opentelemetry and heavily inspired by thi

The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 | A tiny secure-random password generator
A tiny secure-random password generator

go-psw A tiny golang tool for generating a crypto-random password in a terminal. Installation go install github.com/hedhyw/go-psw/cmd/[email protected] Usage

Super short, fully unique, non-sequential and URL friendly Ids

Generator of unique non-sequential short Ids The package shortidenables the generation of short, fully unique, non-sequential and by default URL frien

Universally Unique Lexicographically Sortable Identifier (ULID) in Go

Universally Unique Lexicographically Sortable Identifier A Go port of alizain/ulid with binary format implemented. Background A GUID/UUID can be subop

✨ Generate unique IDs (Port of Node package "generate-snowflake" to Golang)

✨ Generate Snowflake Generate unique IDs. Inspired by Twitter's Snowflake system. 📦 Installation Initialize your project (go mod init example.com/exa

Tarmac is a unique framework designed for the next generation of distributed systems
Tarmac is a unique framework designed for the next generation of distributed systems

Framework for building distributed services with Web Assembly

make slice items unique in go

make slice items unique in go

Comments
  • invalid operation

    invalid operation

    ../github.com/aidarkhanov/nanoid/nanoid.go:32:11: invalid operation: 2 << (31 - bits.LeadingZeros32(uint32(len(alphabet) - 1 | 1))) (shift count type int, must be unsigned integer)

    It's give me this error when I try to get package with go get github.com/aidarkhanov/nanoid It was working before this commit b8b9271898f48bd1c8c188de997da14b78d3ba91

    bug good first issue 
    opened by aprilcoskun 4
  • Rewrite some code and fixed library behavior

    Rewrite some code and fixed library behavior

    Hello!

    I've fixed alphabet characters set for #2. Also I founded that your for-loop for step variable runs in reversed order. I thought that this is looks not good also because this is not the same different as original implementation.

    Also I've rewrite your code a little bit.

    opened by morozovcookie 2
  • Invalid alphabet string

    Invalid alphabet string

    Hello!

    I am trying read your implementation and docs (I want to generate identifiers only from symbols) - I found it and all right.

    But in your README (you just copy that string, I know :)) you wrote that nanoid used more characters than UUID. I decide to compare your source code and original and found that you used different strings in default mode:

    • you are used string alphabet = "-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW"
    • from original repository let urlAlphabet = 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'

    It is not a problem - I can specify it by myself via Generate, for example. But I think that all general implementation should work the same as original.

    And I think that you should rewrite your code like:

    // GenerateString generates a random string based on
    // alphabet and size.
    func GenerateString(alphabet string, size int) (string, error) {
    	id, err := FormatString(generateRandomBuffer, alphabet, size)
    	if err != nil {
    		return "", err
    	}
    	return id, nil
    }
    
    // New generates a random string.
    func New() (string, error) {
    	return GenerateString(alphabet, size)
    }
    

    Because the original code looks like duplicate logic.

    opened by morozovcookie 1
Owner
Dair Aidarkhanov
Dair Aidarkhanov
Compact, sortable and fast unique IDs with embedded metadata.

A spec for unique IDs in distributed systems based on the Snowflake design, i.e. a coordination-based ID variant. It aims to be friendly to both machi

null 74 Nov 30, 2022
Universally Unique Lexicographically Sortable Identifier (ULID) in Go

Universally Unique Lexicographically Sortable Identifier A Go port of alizain/ulid with binary format implemented. Background A GUID/UUID can be subop

OK Log 3k Dec 8, 2022
✨ Generate unique IDs (Port of Node package "generate-snowflake" to Golang)

✨ Generate Snowflake Generate unique IDs. Inspired by Twitter's Snowflake system. ?? Installation Initialize your project (go mod init example.com/exa

Barış DEMİRCİ 6 Feb 11, 2022
K-Sortable Globally Unique IDs

ksuid ksuid is an efficient, comprehensive, battle-tested Go library for generating and parsing a specific kind of globally unique identifier called a

Segment 3.8k Dec 2, 2022
A network service for generating unique ID numbers inspired by Twitter's Snowflake.

Hanabira Hanabira is a network service for generating unique ID numbers inspired by Twitter's Snowflake. How to run hanabira-cluster and etcd-cluster

Shooketh 0 Jan 13, 2022
A generator library for concise, unambiguous and URL-safe UUIDs

shortuuid A Go library that generates concise, unambiguous, URL-safe UUIDs. Based on and compatible with the Python library shortuuid. Often, one need

Peter Lithammer 974 Nov 27, 2022
❄ An Lock Free ID Generator for Golang based on Snowflake Algorithm (Twitter announced).

❄ An Lock Free ID Generator for Golang based on Snowflake Algorithm (Twitter announced).

徐连波 206 Nov 6, 2022
golang实现的分布式唯一ID生成器distributed id generator,有全局趋势递增、严防时钟漂移、高可用、高性能等特点

ekko-idgenerator是什么 顾名思义,ekko是一个分布式唯一ID生成器,参考了snowFlake思想,但是并不局限于其设计。 名称由来 英雄联盟的时间刺客ekko 特点 易用,最大限度保证系统的易用性,支持Get与MultiGet; 高并发,单机每秒100w个唯一ID生成; 高可用,理

leechanx 3 Aug 14, 2021
Snowflake - Simple twitter's snowflake uniquely identifiable descriptors (IDs) format generator for Go

Snowflake Dead simple and fast Twitter's snowflake id generator in Go. Installation go get github.com/HotPotatoC/snowflake Usage Generating a snowflak

Juan Christian 4 Oct 6, 2022
Generate, encode, and decode UUIDs v1 with fast or cryptographic-quality random node identifier.

A Go package for generating and manipulating UUIDs Generate, encode, and decode UUIDs v1, as defined in RFC 4122, in Go. Project Status v1.1.0 Stable:

AGExt 15 Sep 27, 2022