9.2. Universally Unique Identifier (UUID)¶
The Datastore accepts a UUID (a unique identifier) as the key to its key-value storage.
To do this, you will use the userlib.UUIDNew()
and
userlib.UUIDFromBytes()
functions, which are wrappers around the functions
of the same name in the Google UUID library. These wrappers exist because
they allow the userlib to provide more useful debugging functionality.
Below are functions you can use to generate a UUID, either randomly from scratch, or deterministically from a piece of data.
-
userlib.
UUIDNew
()¶ Returns a randomly generated UUID.
- Return type
userlib.UUID
Example:
new_UUID := userlib.UUIDNew()
-
userlib.
UUIDFromBytes
(b []byte) (uuid UUID, err error)¶ FromBytes creates a new UUID from the first sixteen bytes of a byte slice. Returns an error if the slice is less than length 16. The bytes are copied from the slice.
Note that the generated UUID will reveal information about the input bytestring. In other words, the generated UUID provides no confidentiality for the input data in byte slice b.
- Parameters
b ([]byte) – Byte slice from which to create a UUID.
- Return type
userlib.UUID, error
Example:
(new_UUID, _) := userlib.UUIDFromBytes(byte_slice[:16])