uuid

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 9 Imported by: 1

README

uuid

A simple module used to generate Version 4, Variant 1 UUIDs as per RFC 4122.

Usage Example

userID := uuid.New()
fmt.Printf("%v\n", userID) // 2c99fffe-56b8-4453-9f6a-32a8d7fbde80

Support

The uuid.UUID type supports marshalling and unmarshalling from JSON and works with most standard UUID/GUID database types.


Icons made by Freepik from www.flaticon.com.

Documentation

Index

Constants

View Source
const Size = 16

Size is the size, in bytes, of a UUID.

View Source
const StringSize = 36

StringSize is the size, in bytes, of a UUID string with hyphens.

Variables

View Source
var Empty = UUID{}

Empty returns the empty UUID - that is, a UUID with all 128-bits as zero. Contrary to popular belief, the Empty UUID can never be generated, even under Version 4 UUIDs.

View Source
var ErrInvalidSize = errors.New("the provided UUID was not 16 bytes in length")

ErrInvalidSize is returned when parsing a UUID that is not 16 bytes in length.

Functions

This section is empty.

Types

type UUID

type UUID [Size]byte

UUID stores a single 128-bit UUID.

func New

func New() UUID

New creates a new Version 4, Variant 1 UUID using the standard library CSPRNG. It is assumed that this CSPRNG is always available to ease error checking when generating UUIDs. If random bytes cannot be read, this call will panic.

func NewFrom

func NewFrom(r io.Reader) (UUID, error)

NewFrom creates a new Version 4, Variant 1 UUID using the provided source of random numbers.

func Parse

func Parse(str string) (UUID, error)

Parse parses the provided UUID string to a UUID structure. Parse allows UUIDs with different versions and variants.

func (UUID) MarshalJSON

func (id UUID) MarshalJSON() ([]byte, error)

MarshalJSON marshals the UUID into a JSON string literal.

func (*UUID) Scan

func (id *UUID) Scan(src interface{}) error

Scan implements the logic used to read a database value.

func (UUID) String

func (id UUID) String() string

String converts the UUID to the standard UUID string representation with hyphens.

func (*UUID) UnmarshalJSON

func (id *UUID) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals the provided JSON literal into the UUID.

func (UUID) Value

func (id UUID) Value() (driver.Value, error)

Value returns a database-driver-friendly representation of the UUID.

Jump to

Keyboard shortcuts

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