identifier

package
v4.24.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2017 License: BSD-3-Clause Imports: 13 Imported by: 2

Documentation

Overview

Package identifier of the Tideland Go Library provides different ways to produce identifiers out of diffent input data as well as UUIDs.

The UUID generation can be done according the versions 1, 3, 4, and 5. Other identifier types are based on passed data or types. Here the individual parts are harmonized and concatenated by the passed seperators. It is the users responsibility to check if the identifier is unique in its context.

Index

Constants

View Source
const (
	ErrInvalidHexLength = iota + 1
	ErrInvalidHexValue
)

Error codes of the identifier package.

View Source
const (
	UUIDv1 byte = 1
	UUIDv3 byte = 3
	UUIDv4 byte = 4
	UUIDv5 byte = 5

	UUIDVariantNCS       byte = 0
	UUIDVariantRFC4122   byte = 4
	UUIDVariantMicrosoft byte = 6
	UUIDVariantFuture    byte = 7
)

UUID versions and variants.

Variables

This section is empty.

Functions

func Identifier

func Identifier(parts ...interface{}) string

Identifier works like SepIdentifier but the separator is set to be a colon.

func IsInvalidHexLengthError

func IsInvalidHexLengthError(err error) bool

IsInvalidHexLengthError returns true, if the error signals that the passed hex string for a UUID hasn't the correct size of 32.

func IsInvalidHexValueError

func IsInvalidHexValueError(err error) bool

IsInvalidHexValueError returns true, if the error signals an invalid hex string as input.

func JoinedIdentifier

func JoinedIdentifier(identifiers ...string) string

JoinedIdentifier builds a new identifier, joinded with the colon as the separator.

func LimitedSepIdentifier

func LimitedSepIdentifier(sep string, limit bool, parts ...interface{}) string

LimitedSepIdentifier builds an identifier out of multiple parts, all as lowercase strings and concatenated with the separator Non letters and digits are exchanged with dashes and reduced to a maximum of one each. If limit is true only 'a' to 'z' and '0' to '9' are allowed.

func SepIdentifier

func SepIdentifier(sep string, parts ...interface{}) string

SepIdentifier builds an identifier out of multiple parts, all as lowercase strings and concatenated with the separator Non letters and digits are exchanged with dashes and reduced to a maximum of one each.

func TypeAsIdentifierPart

func TypeAsIdentifierPart(i interface{}) string

TypeAsIdentifierPart transforms the name of the arguments type into a part for identifiers. It's splitted at each uppercase char, concatenated with dashes and transferred to lowercase.

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 NewUUID

func NewUUID() UUID

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

func NewUUIDByHex

func NewUUIDByHex(source string) (UUID, error)

NewUUIDByHex creates a UUID based on the passed hex string which has to have the length of 32 bytes.

func NewUUIDv1

func NewUUIDv1() (UUID, error)

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

func NewUUIDv3

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

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

func NewUUIDv4

func NewUUIDv4() (UUID, error)

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

func NewUUIDv5

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

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

func UUIDNamespaceDNS

func UUIDNamespaceDNS() UUID

UUIDNamespaceDNS returns the DNS namespace UUID.

func UUIDNamespaceOID

func UUIDNamespaceOID() UUID

UUIDNamespaceOID returns the OID namespace UUID.

func UUIDNamespaceURL

func UUIDNamespaceURL() UUID

UUIDNamespaceURL returns the URL namespace UUID.

func UUIDNamespaceX500

func UUIDNamespaceX500() UUID

UUIDNamespaceX500 returns the X.500 namespace UUID.

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() byte

Variant returns the variant of the UUID.

func (UUID) Version

func (uuid UUID) Version() byte

Version returns the version number of the UUID algorithm.

Jump to

Keyboard shortcuts

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