uuid

package
v0.0.0-...-b17460c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Size = 16

	V7 byte = 7
)
View Source
const (
	VariantNCS = iota
	VariantRFC4122
	VariantMicrosoft
	VariantFuture
)

Variables

View Source
var ErrBigTime = errors.New("uuid: timestamp overflow, cannot generate")

Functions

func TimeFromV7

func TimeFromV7(u UUID) (time.Time, error)

Types

type UUID

type UUID [Size]byte

func Must

func Must(u UUID, err error) UUID

func NewV7

func NewV7() (UUID, error)

NewV7 This is an implementation of a UUIDv7-compatible ID generator. The reference used was the latest version of the draft IETF RFC4122bis specification at

https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-14.html

The UUIDv7 bit layout is

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           unix_ts_ms                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          unix_ts_ms           |  ver  |       rand_a          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|var|                        rand_b                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            rand_b                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The fields are to be filled as follows:

  1. unix_ts_ms: a 48-bit Unix millisecond timestamp.
  2. ver: the 4-bit literal value 0b0111 (7) denoting the UUID version.
  3. rand_a: a 12-bit pseudo-random value.
  4. var: the 2-bit literal value 0b10 (2) denoting the UUID variant.
  5. rand_b: a 62-bit pseudo-random value.

The specification allows for additional monotonicity guarantees within the millisecond by incrementing the value of rand_b by a random integer of any desired length for additional UUIDs generated within a single timestamp tick. This may become relevant in future. For now, we generate a new 74-bit pseudo-random value for every generated UUID.

func (UUID) String

func (u UUID) String() string

func (UUID) Variant

func (u UUID) Variant() int

func (UUID) Version

func (u UUID) Version() byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL