uuid

package
v1.20240719.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 8 Imported by: 35

Documentation

Overview

Package uuid is a basic implementation of the version 4 spec of the universal unique identifier.

Index

Constants

View Source
const (
	ErrParseInvalidUUIDInput = ex.Class("parse uuid: existing uuid is invalid")
	// ErrParseEmpty            = ex.Class("parse uuid: input is empty")
	ErrParseInvalidLength    = ex.Class("parse uuid: input is an invalid length")
	ErrParseIllegalCharacter = ex.Class("parse uuid: illegal character")
)

Error Classes

View Source
const (
	ErrInvalidScanSource ex.Class = "uuid: invalid scan source"
)

ErrInvalidScanSource is an error returned by scan.

Variables

This section is empty.

Functions

func ParseExisting

func ParseExisting(uuid *UUID, corpus string) error

ParseExisting parses into an existing UUID.

Types

type UUID

type UUID []byte

UUID represents a unique identifier conforming to the RFC 4122 standard. UUIDs are a fixed 128bit (16 byte) binary blob.

var (
	Zero UUID = Empty()
)

Zero is the empty UUID.

func Empty

func Empty() UUID

Empty returns an empty uuid.

func MustParse

func MustParse(corpus string) UUID

MustParse parses a uuid and will panic if there is an error.

func Parse

func Parse(corpus string) (UUID, error)

Parse parses a uuidv4 from a given string. valid forms are: - {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

func V4

func V4() UUID

V4 Create a new UUID version 4.

func (UUID) Compare

func (uuid UUID) Compare(other UUID) int

Compare returns a comparison between the two uuids.

func (UUID) Equal

func (uuid UUID) Equal(other UUID) bool

Equal returns if a uuid is equal to another uuid.

func (UUID) Format

func (uuid UUID) Format(s fmt.State, verb rune)

Format allows for conditional expansion in printf statements based on the token and flags used.

func (UUID) IsV4

func (uuid UUID) IsV4() bool

IsV4 returns true iff uuid has version number 4, variant number 2, and length 16 bytes

func (UUID) IsZero

func (uuid UUID) IsZero() bool

IsZero returns if the uuid is unset.

func (UUID) Marshal

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

Marshal implements bytes marshal.

func (UUID) MarshalJSON

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

MarshalJSON marshals a uuid as json.

func (UUID) MarshalTo

func (uuid UUID) MarshalTo(data []byte) (n int, err error)

MarshalTo marshals the uuid to a buffer.

func (UUID) MarshalYAML

func (uuid UUID) MarshalYAML() (interface{}, error)

MarshalYAML marshals a uuid as yaml.

func (*UUID) Scan

func (uuid *UUID) Scan(src interface{}) error

Scan scans a uuid from a db value.

func (*UUID) Size

func (uuid *UUID) Size() int

Size returns the size of the uuid.

func (UUID) String

func (uuid UUID) String() string

String is an alias for `ToShortString`.

func (UUID) ToFullString

func (uuid UUID) ToFullString() string

ToFullString returns a "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" hex representation of a uuid.

func (UUID) ToShortString

func (uuid UUID) ToShortString() string

ToShortString returns a hex representation of the uuid.

func (*UUID) Unmarshal

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

Unmarshal implements bytes unmarshal.

func (*UUID) UnmarshalJSON

func (uuid *UUID) UnmarshalJSON(corpus []byte) error

UnmarshalJSON unmarshals a uuid from json.

func (*UUID) UnmarshalYAML

func (uuid *UUID) UnmarshalYAML(unmarshaler func(interface{}) error) error

UnmarshalYAML unmarshals a uuid from yaml.

func (UUID) Value

func (uuid UUID) Value() (driver.Value, error)

Value returns a sql driver value.

func (UUID) Version

func (uuid UUID) Version() byte

Version returns the version byte of a uuid.

Jump to

Keyboard shortcuts

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