uuid

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: BSD-3-Clause Imports: 9 Imported by: 2

README

Tideland Go UUID

GitHub release GitHub license Go Module GoDoc Workflow Go Report Card

Description

Tideland Go UUID provides functions for the creation and working on UUIDs in the versions 1, 3, 4, and 5. More are planned.

I hope you like it. ;)

Contributors

Documentation

Overview

Package uuid provides helpful functions for the work with UUIDs. Most important are the functions for the generation of UUIDs in the different versions 1, 3, 4, and 5. More versions are planned. It also can analyse and format those unique identifiers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UUID

type UUID [16]byte

UUID represents a universal identifier with 16 bytes. See http://en.wikipedia.org/wiki/Universally_unique_identifier.

func NamespaceDNS

func NamespaceDNS() UUID

NamespaceDNS returns the DNS namespace UUID for a v3 or a v5.

func NamespaceOID

func NamespaceOID() UUID

NamespaceOID returns the OID namespace UUID for a v3 or a v5.

func NamespaceURL

func NamespaceURL() UUID

NamespaceURL returns the URL namespace UUID for a v3 or a v5.

func NamespaceX500

func NamespaceX500() UUID

NamespaceX500 returns the X.500 namespace UUID for a v3 or a v5.

func New

func New() UUID

New returns a new UUID with based on the default version 4.

func NewV1

func NewV1() (UUID, error)

NewV1 generates a new UUID based on version 1 (MAC address and date-time).

func NewV3

func NewV3(ns UUID, name []byte) (UUID, error)

NewV3 generates a new UUID based on version 3 (MD5 hash of a namespace and a name).

func NewV4

func NewV4() (UUID, error)

NewV4 generates a new UUID based on version 4 (strong random number).

func NewV5

func NewV5(ns UUID, name []byte) (UUID, error)

NewV5 generates a new UUID based on version 5 (SHA1 hash of a namespace and a name).

func Parse added in v0.1.1

func Parse(source string) (UUID, error)

Parse creates a UUID based on the given hex string which has to have one of the following formats:

- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The net data always has to have the length of 32 bytes.

func (UUID) Copy

func (uuid UUID) Copy() UUID

Copy returns a copy of the UUID.

func (UUID) Raw

func (uuid UUID) Raw() [16]byte

Raw returns a copy of the UUID bytes.

func (UUID) ShortString

func (uuid UUID) ShortString() string

ShortString returns a hexadecimal string representation without separators.

func (UUID) String

func (uuid UUID) String() string

String returns a hexadecimal string representation with standardized separators.

func (UUID) Variant

func (uuid UUID) Variant() Variant

Variant returns the variant of the UUID.

func (UUID) Version

func (uuid UUID) Version() Version

Version returns the version number of the UUID algorithm.

type Variant added in v0.1.1

type Variant byte

Variant represents a UUID's variant.

const (
	VariantNCS       Variant = 0 // Reserved, NCS backward compatibility.
	VariantRFC4122   Variant = 4 // The variant specified in RFC4122.
	VariantMicrosoft Variant = 6 // Reserved, Microsoft Corporation backward compatibility.
	VariantFuture    Variant = 7 // Reserved for future definition.
)

type Version added in v0.1.1

type Version byte

Version represents a UUID's version.

const (
	V1 Version = 1
	V3 Version = 3
	V4 Version = 4
	V5 Version = 5
)

UUID versions and variants.

Jump to

Keyboard shortcuts

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