Documentation
¶
Overview ¶
Package uuid provides functions for generating and formatting UUIDs as specified in RFC 4122.
Index ¶
- Variables
- type UUID
- func Must(u UUID, err error) UUID
- func NewV3(namespace UUID, name []byte) UUID
- func NewV4() (UUID, error)
- func NewV4FromRand(r io.Reader) (UUID, error)
- func NewV5(namespace UUID, name []byte) UUID
- func NewV7(now time.Time) (UUID, error)
- func NewV7FromRand(now time.Time, r io.Reader) (UUID, error)
- func Parse(b []byte) (UUID, error)
- func ParseString(s string) (UUID, error)
- func (u UUID) Bytes() []byte
- func (u UUID) Format() [36]byte
- func (u UUID) IsZero() bool
- func (u UUID) MarshalBinary() ([]byte, error)
- func (u UUID) MarshalJSON() ([]byte, error)
- func (u UUID) MarshalText() ([]byte, error)
- func (u *UUID) Scan(src interface{}) error
- func (u UUID) String() string
- func (u UUID) Time() (time.Time, bool)
- func (u *UUID) UnmarshalBinary(data []byte) error
- func (u *UUID) UnmarshalJSON(b []byte) error
- func (u *UUID) UnmarshalText(text []byte) error
- func (u UUID) Value() (driver.Value, error)
- func (u UUID) Version() int
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidUUID = errors.New("uuid: invalid uuid provided")
ErrInvalidUUID represents the error returned during parsing when the provided bytes do not represent a valid UUID.
Functions ¶
This section is empty.
Types ¶
type UUID ¶
type UUID [16]byte
UUID represents a universally unique identifier made up of 128 bits.
For more information see: https://en.wikipedia.org/wiki/Universally_unique_identifier
func NewV3 ¶
NewV3 uses the provided namespace and name to generate and return a new v3 UUID using MD5 hashing, as per RFC 4122.
func NewV4 ¶
NewV4 generates and returns a new v4 UUID using random bytes, as per RFC 4122. If an error occurs while reading from "crypto/rand", it is returned.
func NewV4FromRand ¶ added in v1.5.0
NewV4FromRand generates and returns a new v4 UUID using the random bytes returned from the provided io.Reader.
func NewV5 ¶
NewV5 uses the provided namespace and name to generate and return a new v5 UUID using SHA1 hashing, as per RFC 4122.
func NewV7 ¶ added in v1.3.0
NewV7 uses the provided timestamp to generate and return a new V7 UUID, as per RFC 4122. If an error occurs while reading from "crypto/rand", it is returned.
func NewV7FromRand ¶ added in v1.5.0
NewV7FromRand uses the provided timestamp and random io.Reader to return a new V7 UUID, as per RFC 4122.
func Parse ¶ added in v0.2.0
Parse parses the provided UUID bytes, returning the UUID or any error encountered. The following formats are provided:
16 byte raw, binary UUID 32 byte hexadecimal formatted UUID without dashes e.g. 9e754ef68dd94903af437aea99bfb1fe 36 byte hexadecimal formatted UUID e.g "9e754ef6-8dd9-4903-af43-7aea99bfb1fe"
func ParseString ¶ added in v0.2.0
ParseString parses the provided UUID string using the same rules as Parse.
func (UUID) Bytes ¶ added in v1.0.0
Bytes returns the hexadecimal format of the UUID as a slice of 36 bytes.
Example: 9e754ef6-8dd9-5903-af43-7aea99bfb1fe
func (UUID) Format ¶
Format returns the hexadecimal format of the UUID as an array of 36 bytes.
Example: 9e754ef6-8dd9-5903-af43-7aea99bfb1fe
func (UUID) IsZero ¶ added in v1.4.0
IsZero returns true if the UUID cotains all zeros (the default value).
func (UUID) MarshalBinary ¶ added in v1.0.0
MarshalBinary implements the BinaryMarshaler interface. It returns a byte slice representing the 16 byte binary representation of the UUID.
func (UUID) MarshalJSON ¶ added in v1.0.0
MarshalJSON implements the json Marshaler interface. It returns a byte slice representing the JSON string of a 36 byte hexadecimal representation of the UUID.
func (UUID) MarshalText ¶ added in v1.0.0
MarshalText implements the TextMarshaler interface. It returns a byte slice representing the 36 byte hexadecimal representation of the UUID.
func (*UUID) Scan ¶ added in v1.2.0
Scan implements the sql Scanner interface. It reads the UUID from src into u.
func (UUID) String ¶ added in v1.0.0
String returns the human-readable, hexadecimal format of the UUID as a string with a length of 36 bytes.
Example: 9e754ef6-8dd9-5903-af43-7aea99bfb1fe
func (UUID) Time ¶ added in v1.3.0
Time returns the embedded timestamp of the UUID, and a boolean indicating if a timestamp was successfully parsed.
The provided UUID MUST be version 7.
func (*UUID) UnmarshalBinary ¶ added in v1.2.0
UnmarshalBinary implements the BinaryUnmarshaler interface. It reads the binary UUID from data into u.
func (*UUID) UnmarshalJSON ¶ added in v1.2.0
UnmarshalJSON implements the json Unmarshaler interface. It reads the json UUID b into u.
func (*UUID) UnmarshalText ¶ added in v1.2.0
UnmarshalText implements the TextUnmarshaler interface. It reads the text UUID from text into u.