uuid

package module
v0.0.0-...-cf1f1b5 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

This uuid package implements UUIDv7¹ with additional convenience methods.

¹ https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html#name-uuid-version-7

Index

Constants

View Source
const (
	UUIDv7 = Version(7)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID [6]byte

Last 48 bits of random part.

func (ID) String

func (id ID) String() string

String returns the ID string.

type UUID

type UUID [size]byte

Representation of an UUID version 7.

var (
	// 00000000-0000-0000-0000-000000000000
	Nil UUID = [size]byte{}
	// FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
	Max UUID = [size]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
)

func MustParse

func MustParse(uuid string) UUID

MustParse takes an UUID as string and returns an UUID type or panic.

func New

func New() (UUID, error)

New generates an UUIDv7 and nil return or a Nil UUID and an error message.

func Now

func Now() UUID

Now generates an UUIDv7 like New() or panics on error.

func Parse

func Parse(uuid string) (UUID, error)

Parse takes an UUID as string and returns an UUIDv7 or Nil with an error.

func (UUID) After

func (uuid UUID) After(other UUID) bool

After compares the creation dates of uuid with other.

func (UUID) Before

func (uuid UUID) Before(other UUID) bool

Before compares the creation dates of uuid with other.

func (UUID) Bytes

func (uuid UUID) Bytes() []byte

Bytes returns the 16 raw bytes of the UUIDv7 as []byte.

func (UUID) Date

func (uuid UUID) Date() time.Time

Date returns the date of UUIDv7 creation.

func (UUID) Id

func (uuid UUID) Id() ID

Id() returns the random non-unique ID from the UUIDv7.

func (UUID) IsMax

func (uuid UUID) IsMax() bool

IsMax() compares given UUIDv7 against Max.

func (UUID) IsNil

func (uuid UUID) IsNil() bool

IsNil() compares given UUIDv7 against Nil.

func (UUID) IsValid

func (uuid UUID) IsValid() bool

IsValid checks if the UUID is a valid UUIDv7.

func (UUID) String

func (uuid UUID) String() string

String returns the UUIDv7 string with dash separators.

func (UUID) Version

func (uuid UUID) Version() Version

Version returns the version. Usually see constant UUIDv7.

type UUIDs

type UUIDs []UUID

UUIDs is a collection of UUIDv7 that implements the sort interface.

func (UUIDs) Len

func (u UUIDs) Len() int

func (UUIDs) Less

func (u UUIDs) Less(i, j int) bool

func (UUIDs) Swap

func (u UUIDs) Swap(i, j int)

type Version

type Version byte

A Version represents a UUID's version.

Directories

Path Synopsis
cmd
uuidv7 Module

Jump to

Keyboard shortcuts

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