uuid

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package uuid is a port of https://github.com/gofrs/uuid with functions only for parsing UUID from string.

Index

Constants

View Source
const (
	V1 byte // Version 1 (date-time and MAC address)

	V3 // Version 3 (namespace name-based)
	V4 // Version 4 (random)
	V5 // Version 5 (namespace name-based)
	V6 // Version 6 (k-sortable timestamp and random data, field-compatible with v1) [peabody draft]
	V7 // Version 7 (k-sortable timestamp and random data) [peabody draft]

)

UUID versions.

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

UUID layout variants.

View Source
const Size = 16

Size of a UUID in bytes.

Variables

View Source
var (
	ErrTooShort               = errors.New("too short")
	ErrTooLong                = errors.New("too long")
	ErrInvalidHyphenPlacement = errors.New("invalid hyphen placement")
	ErrInvalid                = errors.New("invalid")
)
View Source
var Nil = UUID{}

Nil is the nil UUID, as specified in RFC-4122, that has all 128 bits set to zero.

Functions

This section is empty.

Types

type UUID

type UUID [Size]byte

UUID is an array type to represent the value of a UUID, as defined in RFC-4122.

func CanonicalFromString

func CanonicalFromString(input string) (UUID, error)

func FromString

func FromString(input string) (UUID, error)

FromString returns a UUID parsed from the input string. Input is expected in a form accepted by UnmarshalText.

func (UUID) IsNil

func (u UUID) IsNil() bool

IsNil returns if the UUID is equal to the nil UUID.

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. Following formats are supported:

"6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"{6ba7b810-9dad-11d1-80b4-00c04fd430c8}",
"urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
"6ba7b8109dad11d180b400c04fd430c8"
"{6ba7b8109dad11d180b400c04fd430c8}",
"urn:uuid:6ba7b8109dad11d180b400c04fd430c8"

ABNF for supported UUID text representation follows:

URN := 'urn'
UUID-NID := 'uuid'

hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
          'a' | 'b' | 'c' | 'd' | 'e' | 'f' |
          'A' | 'B' | 'C' | 'D' | 'E' | 'F'

hexoct := hexdig hexdig
2hexoct := hexoct hexoct
4hexoct := 2hexoct 2hexoct
6hexoct := 4hexoct 2hexoct
12hexoct := 6hexoct 6hexoct

hashlike := 12hexoct
canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct

plain := canonical | hashlike
uuid := canonical | hashlike | braced | urn

braced := '{' plain '}' | '{' hashlike  '}'
urn := URN ':' UUID-NID ':' plain

func (UUID) ValidVersion

func (u UUID) ValidVersion(versions ...byte) bool

func (UUID) Variant

func (u UUID) Variant() byte

Variant returns the UUID layout variant.

func (UUID) Version

func (u UUID) Version() byte

Version returns the algorithm version used to generate the UUID.

Jump to

Keyboard shortcuts

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