uuid

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 8 Imported by: 5

Documentation

Overview

Package uuid provides a wrapper for handling UUID codes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// IsV1 is used to ensure value is a UUIDv1
	IsV1 = versionRule{/* contains filtered or unexported fields */}
	// IsV4 confirms the UUID is version 4
	IsV4 = versionRule{/* contains filtered or unexported fields */}
	// IsNotZero confirms the UUID is not zero
	IsNotZero = versionRule{/* contains filtered or unexported fields */}
)

Functions

func NodeID

func NodeID() string

NodeID returns the hex representation of the current host bytes

func SetRandomNodeID

func SetRandomNodeID()

SetRandomNodeID is used to generate a random host ID to be used in V1 UUIDs instead of the MAC address. This is stored in the uuid library as a global constant, so should be called just once when starting the application if you're indending to generate V1 UUIDs to get a node ID that won't change.

func Within

func Within(ttl time.Duration) validation.Rule

Within is a validation method that can be used to determine if the UUID corresponds do UUIDv1 standard and was timestamped within the acceptable time to live from now. If time checks are enabled, future UUIDs will not be allowed, this could be a problem.

Types

type UUID

type UUID struct {
	uuid.UUID
}

UUID defines our wrapper for dealing with UUIDs

func MakeV1 added in v0.28.0

func MakeV1() UUID

MakeV1 generates a version 1 UUID.

func MakeV4 added in v0.28.0

func MakeV4() UUID

MakeV4 generates a new completely random UUIDv4.

func MustParse added in v0.17.0

func MustParse(s string) UUID

MustParse will panic if the UUID does not look good.

func NewV1

func NewV1() *UUID

NewV1 generates a version 1 UUID.

func NewV4

func NewV4() *UUID

NewV4 creates a pointer a new completely random UUIDv4.

func Parse

func Parse(s string) (UUID, error)

Parse decodes s into a UUID or provides an error.

func ShouldParse added in v0.51.0

func ShouldParse(s string) UUID

ShouldParse will return a UUID if the string is valid, otherwise it will provide a zero UUID.

func (*UUID) IsZero

func (u *UUID) IsZero() bool

IsZero returns true if the UUID is all zeros.

func (UUID) JSONSchema added in v0.17.0

func (UUID) JSONSchema() *jsonschema.Schema

JSONSchema returns the jsonschema schema object for the UUID.

func (UUID) Timestamp

func (u UUID) Timestamp() time.Time

Timestamp extracts the time. Anything other than a v1 UUID will provide zero time without an error, so ensure your error checks are performed previously.

Jump to

Keyboard shortcuts

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