For the complete documentation index, see llms.txt. This page is also available as Markdown.

Uniqueid

The Uniqueid registry offers functions to generate unique identifiers, such as UUIDs, which are essential for creating distinct and traceable entities in your applications.

You can easily import all the functions from the uniqueid registry by including the following import statement in your code

import "github.com/go-sprout/sprout/registry/uniqueid"

uuidv4

Uuidv4 generates a new random UUID (Universally Unique Identifier) version 4.

Signature

{{ uuidv4 }} // Output(will be different): 3f0c463e-53f5-4f05-a2ec-3c083aa8f937

uuidv7

Uuidv7 generates a new UUID version 7, based on the current Unix time in milliseconds. Unlike a version 4, successive UUIDs are sortable by generation time.

Signature

{{ uuidv7 }} // Output(will be different): 018f5395-4e88-7c2a-9f3b-1d7e4a6c8b90

Prefer uuidv7 over uuidv4 when the identifiers are used as database keys, the time ordering keeps the index locality that a fully random UUID destroys.

uuidv5

Uuidv5 generates a UUID version 5, derived from a namespace and a name using SHA-1. The same namespace and name always produce the same UUID.

Signature

{{ "python.org" | uuidv5 "dns" }} // Output: 886313e1-3b8a-5372-9b90-0c9aee199e5d
{{ "python.org" | uuidv5 "6ba7b810-9dad-11d1-80b4-00c04fd430c8" }} // Output: 886313e1-3b8a-5372-9b90-0c9aee199e5d
{{ "python.org" | uuidv5 "invalid" }} // Error

The namespace is either one of the predefined names dns, url, oid, x500 (case insensitive), or any valid UUID to use a namespace of your own.

uuidv3

Uuidv3 generates a UUID version 3, derived from a namespace and a name using MD5. The same namespace and name always produce the same UUID.

Signature

uuidNil

UuidNil returns the nil UUID, the UUID with all its bits set to zero.

Signature

isUUID

IsUUID checks if the given value is a valid UUID.

Signature

On top of the canonical form, three alternative forms are accepted: the urn prefixed one (urn:uuid:886313e1-…), the braced one ({886313e1-…}) and the one without hyphen (886313e13b8a…). Use uuidVersion if you also need to validate which version you received.

uuidVersion

UuidVersion returns the version of the given UUID.

Signature

uuidTime

UuidTime returns the time embedded in the given UUID. Only the versions carrying a timestamp are supported, namely the versions 1, 2, 6 and 7.

Signature

Last updated