Skip to content

🍄 A generator library for concise, unambiguous and URL-safe UUIDs

License

Notifications You must be signed in to change notification settings

garrettreed/shortuuid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 satori/go.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/renstrom/shortuuid"
)

func main() {
    id := shortuuid.UUID()  // "ajLWxEodc6CmQLHADuKVwD"

    u := shortuuid.New()
    // Note that this will create a new UUID each time its .String() method
    // is invoked.
    fmt.Printf("%s", u)  // Cekw67uyMpBGZLRP2HFVbe
    fmt.Printf("%s", u)  // 4pUYNRFHTG3YVgThPZvCgC
}

To use UUID v5 (instead of the default v4), pass a namespace (DNS or URL) to the .UUID(name string) call:

shortuuid.New().UUID("http://example.com")

License

MIT

About

🍄 A generator library for concise, unambiguous and URL-safe UUIDs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%