9.2. Universally Unique Identifier (UUID)

The Datastore accepts a UUID (a unique identifier) as the key to its key-value storage.

The Google UUID library is already imported for you in proj2.go.

Below are functions you can use to generate a UUID, either randomly from scratch, or deterministically from a piece of data.

uuid.New()

Returns a randomly generated UUID.

Return type

uuid.UUID

Example:

new_UUID := uuid.New()
uuid.FromBytes(b []byte) (uuid UUID, err error)

FromBytes creates a new UUID from a byte slice. Returns an error if the slice does not have a length of 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

uuid.UUID

Example:

(new_UUID, _) := uuid.FromBytes(byte_slice[:16])