• Stars
    star
    1,084
  • Rank 42,698 (Top 0.9 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ„ A generator library for concise, unambiguous and URL-safe UUIDs

shortuuid

Build Status Godoc

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

Often, one needs to use non-sequential IDs in places where users will see them, but the IDs must be as concise and easy to use as possible. shortuuid solves this problem by generating UUIDs using google/uuid and then translating them to base57 using lowercase and uppercase letters and digits, and removing similar-looking characters such as l, 1, I, O and 0.

Usage

package main

import (
	"fmt"

	"github.com/lithammer/shortuuid/v4"
)

func main() {
	u := shortuuid.New() // KwSysDpxcBU9FNhGkn2dCf
}

To use UUID v5 (instead of the default v4), use NewWithNamespace(name string) instead of New().

shortuuid.NewWithNamespace("http://example.com")

It's possible to use a custom alphabet as well, though it has to be 57 characters long.

alphabet := "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxy="
shortuuid.NewWithAlphabet(alphabet) // iZsai==fWebXd5rLRWFB=u

Bring your own encoder! For example, base58 is popular among bitcoin.

package main

import (
	"fmt"

	"github.com/btcsuite/btcutil/base58"
	"github.com/google/uuid"
	"github.com/lithammer/shortuuid/v4"
)

type base58Encoder struct{}

func (enc base58Encoder) Encode(u uuid.UUID) string {
	return base58.Encode(u[:])
}

func (enc base58Encoder) Decode(s string) (uuid.UUID, error) {
	return uuid.FromBytes(base58.Decode(s))
}

func main() {
	enc := base58Encoder{}
	fmt.Println(shortuuid.NewWithEncoder(enc)) // 6R7VqaQHbzC1xwA5UueGe6
}

License

MIT

More Repositories

1

fuzzysearch

🐷 Tiny and fast fuzzy search in Go
Go
979
star
2

go-wiki

A simple HTTP server rendering Markdown styled documents
Go
300
star
3

go-jump-consistent-hash

⚑ Fast, minimal memory, consistent hash algorithm
Go
214
star
4

NeavUI

Development branch of Neav UI
Lua
96
star
5

dedent

Remove any common leading whitespace from multiline strings
Go
89
star
6

python-jump-consistent-hash

Fast, minimal memory, consistent hash algorithm
Python
37
star
7

passbook_flask_example

An example Implementation of a Passbook Webservice in Flask, based on mattt's passbook_rails_example
Python
19
star
8

nvim-diagnosticls

diagnostic-languageserver configuration for Neovim's language server client
Lua
10
star
9

vim-eighties

A simplified and optimized base16-eighties color scheme for Vim
Vim Script
10
star
10

webassets-browserify

Browserify filter for webassets
Python
5
star
11

dotfiles

config files etc.
Shell
4
star
12

prInformation

A lightweight WoW addon for showing various information (fps, gold, friends online etc.)
Lua
2
star
13

advent_of_code_2022

Advent of Code 2022
Rust
2
star
14

imdb-api

Very basic IMDb scraper written for Flask and Heroku
HTML
1
star
15

nvim-pylance

Add Pylance support to nvim-lspconfig
Lua
1
star
16

prButler

Making your life simpler in World of Warcraft
Lua
1
star
17

nSpellTracker

Simple buff, debuff and cooldown tracking based on rFilter3 by Zork
Lua
1
star
18

nFilger

Buff, debuff and cooldown tracker for Neav UI, based on Filger by Nils Ruesch
Lua
1
star
19

prExecute

Plays a notification sound ("Quad damage!" from Quake) when entering execution range for all classes/specs, also plays a tick sound for Drain Soul
Lua
1
star
20

webassets

A webservice to compile and compress various web assets
JavaScript
1
star