Skip to content
Source on GitHub (opens in a new tab)
import "github.com/barevoidco/zelk/core/uuid"

Package uuid generates version 7 UUIDs (RFC 9562), the form zelk gives new session IDs.

A version 7 UUID starts with its creation time in milliseconds, so IDs sort by when they were made, and fills the rest with 74 random bits, so IDs made by different processes never need to coordinate. The package generates and formats UUIDs only: zelk accepts any string as a session ID, so it never needs to parse one.

type UUID [16]byte

UUID is a 128-bit universally unique identifier.

func New() UUID

New returns a version 7 UUID stamped with the current time.

UUIDs made in different milliseconds sort in time order; within one millisecond their order is random. New is safe for concurrent use.

Example

id := uuid.New().String()
fmt.Println(len(id), id[14:15])
// Output: 36 7

Output:

36 7
func (id UUID) String() string

String returns id in the canonical lowercase form, xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx.