uuid

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2019 License: BSL-1.0 Imports: 3 Imported by: 12

README

Go UUIDv4

CircleCI Coveralls Codacy GoDoc

This package contains a minimal implementation of UUIDv4 in Go.

Consider using either Google's implementation or this one by Gofrs if you need additional features.

This package can only generate version 4 UUIDs as defined in RFC 4122

Create a new UUID: uuid.New() (UUID, error)

Convert an UUID to a string: UUID.String() string

Do both in one step: uuid.NewString() (string, error)

Convert a string to an UUID: uuid.Parse(string) (UUID, error)

Convert a byte slice to an UUID: uuid.ParseBytes([]byte) (UUID, error)

Check if UUID contains only zeros: UUID.IsEmpty() bool

Both encoding.Text(Un)Marshaler and encoding.Binary(Un)Marshaler are supported to ensure compatibility with databases and data exchange formats.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewString

func NewString() (string, error)

NewString generates a new UUID v4 and converts it to a string immediately

Types

type UUID

type UUID [16]byte

UUID represents a Universal Unique Identifier as an array containing 16 bytes

func New

func New() (uuid UUID, err error)

New generates a new UUID v4 using a secure random number generator chosen by GoLang

func Parse

func Parse(str string) (UUID, error)

Parse parses a string as a UUID returning either the resulting UUID or an error

func ParseBytes

func ParseBytes(bytes []byte) (uuid UUID, err error)

ParseBytes parses a byte slice and returns the contained BINARY UUID or an error

func (UUID) IsEmpty

func (uuid UUID) IsEmpty() bool

IsEmpty returns if the UUID contains only zeros and is therefore empty and invalid

func (UUID) MarshalBinary

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

MarshalBinary provides encoding.BinaryMarshaler

func (UUID) MarshalText

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

MarshalText provides encoding.TextMarshaler

func (UUID) String

func (uuid UUID) String() string

ToString returns the string representation of a UUID

func (*UUID) UnmarshalBinary

func (uuid *UUID) UnmarshalBinary(in []byte) error

UnmarshalBinary provides encoding.BinaryUnmarshaler

func (*UUID) UnmarshalText

func (uuid *UUID) UnmarshalText(in []byte) error

UnmarshalText provides encoding.TextUnmarshaler

Jump to

Keyboard shortcuts

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