Geração de UUID
Geração de UUID
Seção intitulada “Geração de UUID”Gere identificadores unicos universais. Adaptado para workflows - UUIDs aleatorios retornam valores consistentes em replay.
Carregamento
Seção intitulada “Carregamento”local uuid = require("uuid")UUIDs Aleatorios
Seção intitulada “UUIDs Aleatorios”Versão 1
Seção intitulada “Versão 1”UUID baseado em tempo com timestamp e node ID.
local id, err = uuid.v1()Retorna: string, error
Versão 4
Seção intitulada “Versão 4”UUID aleatorio.
local id, err = uuid.v4()Retorna: string, error
Versão 7
Seção intitulada “Versão 7”UUID ordenado por tempo. Ordenavel por tempo de criação.
local id, err = uuid.v7()Retorna: string, error
UUIDs Deterministicos
Seção intitulada “UUIDs Deterministicos”Versão 3
Seção intitulada “Versão 3”UUID deterministico de namespace e nome usando MD5.
local id, err = uuid.v3(namespace, name)| Parâmetro | Tipo | Descrição |
|---|---|---|
namespace | string | String UUID valida |
name | string | Valor para hash |
Retorna: string, error
Versão 5
Seção intitulada “Versão 5”UUID deterministico de namespace e nome usando SHA-1.
local NS_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"local id, err = uuid.v5(NS_URL, "https://example.com/resource")| Parâmetro | Tipo | Descrição |
|---|---|---|
namespace | string | String UUID valida |
name | string | Valor para hash |
Retorna: string, error
Inspecao
Seção intitulada “Inspecao”Validar
Seção intitulada “Validar”local valid = uuid.validate(input)| Parâmetro | Tipo | Descrição |
|---|---|---|
input | any | Valor para verificar |
Retorna: boolean, error
Obter Versão
Seção intitulada “Obter Versão”local ver, err = uuid.version(id)| Parâmetro | Tipo | Descrição |
|---|---|---|
uuid | string | String UUID valida |
Retorna: integer, error
Obter Variante
Seção intitulada “Obter Variante”local var, err = uuid.variant(id)| Parâmetro | Tipo | Descrição |
|---|---|---|
uuid | string | String UUID valida |
Retorna: string, error (RFC4122, Reserved, Microsoft, Future, NCS ou Invalid)
local info, err = uuid.parse(id)| Parâmetro | Tipo | Descrição |
|---|---|---|
uuid | string | String UUID valida |
Retorna: table, error
Campos da tabela retornada:
version(integer): Versão do UUID (1, 3, 4, 5 ou 7)variant(string): RFC4122, Reserved, Microsoft, Future, NCS ou Invalidtimestamp(integer): Timestamp Unix (apenas v1 e v7)node(string): Node ID (apenas v1)
Formatar
Seção intitulada “Formatar”local formatted, err = uuid.format(id, "standard")local formatted, err = uuid.format(id, "simple")local formatted, err = uuid.format(id, "urn")| Parâmetro | Tipo | Descrição |
|---|---|---|
uuid | string | String UUID valida |
format | string? | standard (padrão), simple ou urn |
Retorna: string, error
| Condição | Tipo | Retentável |
|---|---|---|
| Tipo de input inválido | errors.INVALID | não |
| Formato de UUID inválido | errors.INVALID | não |
| Tipo de formato não suportado | errors.INVALID | não |
| Geração falhou | errors.INTERNAL | não |
Veja Error Handling para trabalhar com erros.