uuid

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidUUIDLength = errors.New("invalid UUID length")
	ErrInvalidUUIDFormat = errors.New("invalid UUID format")
)

Functions

func NewString

func NewString() string

NewString generates a new random UUID v4 and returns it as a string.

Types

type UUID

type UUID [16]byte

UUID is a 128-bit universally unique identifier.

func FromBytes

func FromBytes(b []byte) (UUID, error)

FromBytes creates a UUID from a byte slice.

func FromUint64Pair

func FromUint64Pair(high, low uint64) UUID

FromUint64Pair creates a UUID from two uint64 values.

func MustParse

func MustParse(s string) UUID

MustParse parses a UUID string and panics if it fails.

func New

func New() UUID

New generates a new random UUID v4.

func NewRandom

func NewRandom() (UUID, error)

NewRandom generates a new random UUID v4 and returns an error if the random source fails.

func NewV7

func NewV7() (UUID, error)

NewV7 generates a new UUID v7 based on the current timestamp. UUID v7 uses a Unix timestamp in milliseconds for time-ordering.

func NewV7FromTime

func NewV7FromTime(t time.Time) (UUID, error)

NewV7FromTime generates a UUID v7 from a specific timestamp.

func Parse

func Parse(s string) (UUID, error)

Parse parses a UUID string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

func (UUID) Bytes

func (uuid UUID) Bytes() []byte

Bytes returns the raw bytes of the UUID.

func (UUID) Equal

func (uuid UUID) Equal(other UUID) bool

Equal returns true if two UUIDs are equal.

func (UUID) IsNil

func (uuid UUID) IsNil() bool

IsNil returns true if the UUID is the nil UUID (all zeros).

func (UUID) MarshalBinary

func (uuid UUID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (UUID) MarshalText

func (uuid UUID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*UUID) SetVariant

func (uuid *UUID) SetVariant()

SetVariant sets the variant bits to RFC 4122.

func (*UUID) SetVersion

func (uuid *UUID) SetVersion(v byte)

SetVersion sets the version bits of the UUID.

func (UUID) String

func (uuid UUID) String() string

String returns the string representation of the UUID in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

func (UUID) Timestamp

func (uuid UUID) Timestamp() time.Time

Timestamp returns the timestamp from a UUID v7. For non-v7 UUIDs, the result is undefined.

func (UUID) ToUint64Pair

func (uuid UUID) ToUint64Pair() (uint64, uint64)

ToUint64Pair returns the UUID as two uint64 values (high and low).

func (UUID) URN

func (uuid UUID) URN() string

URN returns the UUID as a URN (urn:uuid:...).

func (*UUID) UnmarshalBinary

func (uuid *UUID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*UUID) UnmarshalText

func (uuid *UUID) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (UUID) Variant

func (uuid UUID) Variant() int

Variant returns the variant of the UUID.

func (UUID) Version

func (uuid UUID) Version() int

Version returns the version of the UUID.

Jump to

Keyboard shortcuts

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