🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/jeancigoli/go-short-uuid

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/jeancigoli/go-short-uuid

v1.0.0
Source
Go
Version published
Created
Source

shortuuid

Transforme UUIDs padrão (128 bits) em identificadores mais curtos, legíveis e amigáveis usando codificação Base58 — tudo isso sem dependências externas para a lógica de codificação.

✨ Totalmente implementado em Go. Inspirado pela biblioteca short-uuid do Node.js.

🚀 Instalação

go get github.com/JeanCigoli/go-short-uuid

🧠 Motivação

UUIDs são ótimos para unicidade, mas podem ser longos e visivelmente "feios". A Base58 reduz o tamanho da string e elimina caracteres ambíguos como 0, O, I e l, tornando os IDs ideais para interfaces humanas, URLs, QR Codes, etc.

✨ Exemplo de uso

package main

import (
	"fmt"
	"github.com/JeanCigoli/go-short-uuid"
)

func main() {
	// Gera um novo UUID curto
	short := shortuuid.New()
	fmt.Println("UUID curto:", short)

	// Codifica um UUID existente
	id := uuid.New()
	encoded, err := shortuuid.EncodeUUID(id)
	fmt.Println("Codificado:", encoded)

	// Decodifica de volta
	decoded, err := shortuuid.DecodeUUID(encoded)
	if err != nil {
		panic(err)
	}
	fmt.Println("Decodificado:", decoded)
}

🔧 API

func New() string

Gera um novo UUID (v4) e retorna sua representação em Base58.

func EncodeUUID(id string) (string, error)

Codifica uma uuid para Base58.

func DecodeUUID(s string) (string, error)

Decodifica uma string Base58 de volta para uuid.

🧪 Testes

go test ./...

📜 Licença

MIT © Jean Cigoli

FAQs

Package last updated on 09 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts