Link Search Menu Expand Document

8.2 UUID

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

To do this, you will use the uuid.New() and uuid.FromBytes() functions, from 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.

The uuid library also provides uuid.UUIDNil, a UUID consisting of all zeros to represent a nil value.


Functions

uuid.New() (uuid.UUID)

Returns a randomly generated UUID.

Returns
uuid.UUID


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.

Parameters
b ([]byte) - byte slice from which to create a UUID.

Returns
uuid (uuid.UUID)
err (error)