uuid

package module
v1.0.1-0...-abc8f6f Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

README

uuid

Package uuid implements UUID RFC 4122.

Usage

Generating
Time-Based (Version 1)
uuid.NewTimeBased() (uuid.UUID, error)
uuid.NewV1() (uuid.UUID, error)
DCE Security (Version 2)
uuid.NewDCESecurity(uuid.Domain) (uuid.UUID, error)
uuid.NewV2(uuid.Domain) (uuid.UUID, error)
Name-Based uses MD5 hashing (Version 3)
uuid.NewNameBasedMD5(namespace, name string) (uuid.UUID, error)
uuid.NewV3(namespace, name string) (uuid.UUID, error)
Random (Version 4)
uuid.NewRandom() (uuid.UUID, error)
uuid.NewV4() (uuid.UUID, error)
Name-Based uses SHA-1 hashing (Version 5)
uuid.NewNameBasedSHA1(namespace, name string) (uuid.UUID, error)
uuid.NewV5(namespace, name string) (uuid.UUID, error)
Styles
  • Standard: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12, length: 36)
  • Without Dash: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (length: 32)
Formatting & Parsing
uuid.UUID.String() string                        // format to standard style
uuid.UUID.Format(uuid.Style) string              // format to uuid.StyleStandard or uuid.StyleWithoutDash

uuid.Parse(string) (uuid.UUID, error)       // parse from UUID string

Documentation

Overview

Package uuid implements UUID described in RFC 4122.

Index

Constants

View Source
const (
	// DomainUser represents POSIX UID domain.
	DomainUser = Domain(dcesecurity.User)
	// DomainGroup represents POSIX GID domain.
	DomainGroup = Domain(dcesecurity.Group)
)
View Source
const (
	// LayoutInvalid represents invalid layout.
	LayoutInvalid = Layout(internal.LayoutInvalid)
	// LayoutNCS represents the layout: Reserved, NCS backward compatibility.
	LayoutNCS = Layout(internal.LayoutNCS)
	// LayoutRFC4122 represents the layout: The variant specified in RFC 4122.
	LayoutRFC4122 = Layout(internal.LayoutRFC4122)
	// LayoutMicrosoft represents the layout: Reserved, Microsoft Corporation backward compatibility.
	LayoutMicrosoft = Layout(internal.LayoutMicrosoft)
	// LayoutFuture represents the layout: Reserved for future definition.
	LayoutFuture = Layout(internal.LayoutFuture)
)
View Source
const (
	NamespaceDNS  = namebased.NamespaceDNS  // "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
	NamespaceURL  = namebased.NamespaceURL  // "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
	NamespaceOID  = namebased.NamespaceOID  // "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
	NamespaceX500 = namebased.NamespaceX500 // "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
)

Standard Namespaces.

View Source
const (
	// VersionUnknown represents unknown version.
	VersionUnknown = Version(internal.VersionUnknown)
	// VersionTimeBased represents the time-based version (Version 1).
	VersionTimeBased = Version(internal.VersionTimeBased)
	// VersionDCESecurity represents the DCE security version, with embedded POSIX UIDs (Version 2).
	VersionDCESecurity = Version(internal.VersionDCESecurity)
	// VersionNameBasedMD5 represents the name-based version that uses MD5 hashing (Version 3).
	VersionNameBasedMD5 = Version(internal.VersionNameBasedMD5)
	// VersionRandom represents the randomly or pseudo-randomly generated version (Version 4).
	VersionRandom = Version(internal.VersionRandom)
	// VersionNameBasedSHA1 represents the name-based version that uses SHA-1 hashing (Version 5).
	VersionNameBasedSHA1 = Version(internal.VersionNameBasedSHA1)
)

Versions.

Short names of versions.

Variables

View Source
var (
	// Nil represents the Nil UUID (00000000-0000-0000-0000-000000000000).
	Nil = UUID{}
)

Functions

func IsValid

func IsValid(uuid string) bool

IsValid reports whether the passed string is a valid uuid string.

Types

type Domain

type Domain byte

Domain represents the identifier for a local domain.

type Layout

type Layout byte

Layout represents the layout of UUID. See page 5 in RFC 4122.

func (Layout) String

func (l Layout) String() string

String returns English description of layout.

type Style

type Style byte

Style represents the style of UUID string.

const (
	// StyleStandard represents the standard style of UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12, length: 36).
	StyleStandard Style = iota + 1
	// StyleWithoutDash represents the style without dash of UUID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (length: 32).
	StyleWithoutDash
)

func (Style) String

func (s Style) String() string

String returns English description of style.

type UUID

type UUID [16]byte

UUID respresents an UUID type compliant with specification in RFC 4122.

func New

func New() (UUID, error)

New is short of NewRandom.

func NewDCESecurity

func NewDCESecurity(domain Domain) (UUID, error)

NewDCESecurity returns a new DCE security UUID (version 2).

func NewNameBasedMD5

func NewNameBasedMD5(namespace, name string) (UUID, error)

NewNameBasedMD5 returns a new name based UUID with MD5 hash (version 3).

func NewNameBasedSHA1

func NewNameBasedSHA1(namespace, name string) (UUID, error)

NewNameBasedSHA1 returns a new name based UUID with SHA1 hash (version 5).

func NewRandom

func NewRandom() (UUID, error)

NewRandom returns a new random UUID (version 4).

func NewTimeBased

func NewTimeBased() (UUID, error)

NewTimeBased returns a new time based UUID (version 1).

func NewV1

func NewV1() (UUID, error)

NewV1 is short of NewTimeBased.

func NewV2

func NewV2(domain Domain) (UUID, error)

NewV2 is short of NewDCESecurity.

func NewV3

func NewV3(namespace, name string) (UUID, error)

NewV3 is short of NewNameBasedMD5.

func NewV4

func NewV4() (UUID, error)

NewV4 is short of NewRandom.

func NewV5

func NewV5(namespace, name string) (UUID, error)

NewV5 is short of NewNameBasedSHA1.

func Parse

func Parse(str string) (UUID, error)

Parse parses the UUID string.

func (UUID) Equal

func (u UUID) Equal(another UUID) bool

Equal returns true if current uuid equal to passed uuid.

func (UUID) Format

func (u UUID) Format(style Style) string

Format returns the formatted string of UUID.

func (UUID) Layout

func (u UUID) Layout() Layout

Layout returns layout of UUID.

func (UUID) String

func (u UUID) String() string

String returns the string of UUID with standard style(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | 8-4-4-4-12).

func (UUID) Version

func (u UUID) Version() Version

Version returns version of UUID.

type Version

type Version byte

Version represents the version of UUID. See page 7 in RFC 4122.

func (Version) String

func (v Version) String() string

String returns English description of Version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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