MCPcopy Index your code
hub / github.com/lithammer/shortuuid

github.com/lithammer/shortuuid @v4.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.2.0 ↗ · + Follow
46 symbols 145 edges 5 files 9 documented · 20% 40 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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()
    fmt.Println(u) // 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 (at least 2 characters long).
It will automatically sort and remove duplicates from your alphabet to ensure consistency

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

Extension points exported contracts — how you extend this code

Encoder (Interface)
Encoder is an interface for encoding/decoding UUIDs to strings. [1 implementers]
shortuuid.go

Core symbols most depended-on inside this repo

newAlphabet
called by 14
alphabet.go
Encode
called by 8
encoder.go
Encode
called by 5
shortuuid.go
NewWithNamespace
called by 4
shortuuid.go
Decode
called by 4
encoder.go
quoRem64
called by 4
encoder.go
Index
called by 4
alphabet.go
Decode
called by 3
shortuuid.go

Shape

Function 32
Method 10
Struct 3
Interface 1

Languages

Go100%

Modules by API surface

shortuuid_test.go22 symbols
encoder.go9 symbols
shortuuid.go8 symbols
alphabet.go4 symbols
alphabet_test.go3 symbols

For agents

$ claude mcp add shortuuid \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page