uuid

package module
v0.0.0-...-b778010 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: Apache-2.0 Imports: 12 Imported by: 1

README

Discarded, moved to https://github.com/golang-plus/uuid

#Go-UUID

The go-uuid package implements UUID RFC 4122 for golang.

##Import

import "github.com/wayn3h0/go-uuid"

##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 Instance).String() string             // format to standard style
(UUID Instance).Format(uuid.Style) string   // format to uuid.StyleStandard or uuid.StyleWithoutDash

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

##LICENSE

Please check LICENSE file.

Documentation

Index

Constants

View Source
const (
	DomainUser  = Domain(dcesecurity.User)  // POSIX UID domain
	DomainGroup = Domain(dcesecurity.Group) // POSIX GID domain
)

Domains.

View Source
const (
	LayoutInvalid   = Layout(layout.Invalid)   // Invalid
	LayoutNCS       = Layout(layout.NCS)       // Reserved, NCS backward compatibility. (Values: 0x00-0x07)
	LayoutRFC4122   = Layout(layout.RFC4122)   // The variant specified in RFC 4122. (Values: 0x08-0x0b)
	LayoutMicrosoft = Layout(layout.Microsoft) // Reserved, Microsoft Corporation backward compatibility. (Values: 0x0c-0x0d)
	LayoutFuture    = Layout(layout.Future)    // Reserved for future definition. (Values: 0x0e-0x0f)
)

Layouts.

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"
)

Imports namespaces.

View Source
const (
	VersionUnknown       = Version(version.Unknown)       // Unknown
	VersionTimeBased     = Version(version.TimeBased)     // V1: The time-based version
	VersionDCESecurity   = Version(version.DCESecurity)   // V2: The DCE security version, with embedded POSIX UIDs
	VersionNameBasedMD5  = Version(version.NameBasedMD5)  // V3: The name-based version that uses MD5 hashing
	VersionRandom        = Version(version.Random)        // V4: The randomly or pseudo-randomly generated version
	VersionNameBasedSHA1 = Version(version.NameBasedSHA1) // V5: The name-based version that uses SHA-1 hashing
)

Versions.

Short names.

Variables

View Source
var (
	Nil = UUID{} // Nil UUID
)

Functions

This section is empty.

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 (this Layout) String() string

String returns English description of layout.

type Style

type Style byte

Style represents the style of UUID string.

const (
	StyleStandard    Style = iota + 1 // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12, length: 36)
	StyleWithoutDash                  // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (length: 32)
)

Styles.

func (Style) String

func (this 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 same as 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 same as NewTimeBased.

func NewV2

func NewV2(domain Domain) (UUID, error)

NewV2 same as NewDCESecurity.

func NewV3

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

NewV3 same as NewNameBasedMD5.

func NewV4

func NewV4() (UUID, error)

NewV4 same as NewRandom.

func NewV5

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

NewV5 same as NewNameBasedSHA1.

func Parse

func Parse(str string) (UUID, error)

Parse parses the UUID string.

func (UUID) Equal

func (this UUID) Equal(another UUID) bool

Equal returns true if current uuid equal to passed uuid.

func (UUID) Format

func (this UUID) Format(style Style) string

Format returns the formatted string of UUID.

func (UUID) Layout

func (this UUID) Layout() Layout

Layout returns layout of UUID.

func (UUID) String

func (this 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 (this 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 (this Version) String() string

String returns English description of version.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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