uuid

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: MIT Imports: 6 Imported by: 4

README

UUIDv6, 7 and 8

Welcome new contestors, UUIDv6, v7 and v8 in Golang. Nice, awesome, machine-sortable and absolutely unique!

  • UUIDv6 - a highly compatible guy.
  • UUIDv7 - all brand new and shinny. Very awesome.
  • UUIDv8 - strange and implementration specific, to fulfill everyone's dreams and requirements.

For more information visit https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/

Usage

var gen uuid.UUIDv7Generator

//Sets how many bits of nano-second precision you would like to see in your UUID. Don't go under 12, don't exceed 48
gen.Precision = 12

id := gen.Next()


fmt.Println(id.ToString())
//Output:
//060f1cb1ce-8c70-e7b9-f7e4-4b50e3353e

fmt.Println(id.ToBinaryString())
//Output:
//00000110 00001111 00011100 10110001 11001110 10001100 01110000 11100111 10111001 11110111 11100100 01001011 01010000 11100011 00110101 00111110
fmt.Println(id.ToMicrosoftString())
//Output:
//{060F1CB1CE-8C70-E7B9-F7E4-4B50E3353E}

fmt.Println(id.Time())
//Ouput:
//2021-07-16 11:08:28 -0700 PDT

fmt.Println(id.Timestamp())
//Output:
//1626458908

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UUIDv6

type UUIDv6 uuidBase

func UUIDv6FromBytes

func UUIDv6FromBytes(b []byte) (uuid UUIDv6, err error)

UUIDv6FromBytes creates a new UUIDv6 from a slice of bytes and returns an error, if an array length does not equal 16.

type UUIDv7

type UUIDv7 uuidBase

func UUIDv7FromBytes

func UUIDv7FromBytes(b []byte) (uuid UUIDv7, err error)

UUIDv7FromBytes creates a new UUIDv7 from a slice of bytes and returns an error, if an array length does not equal 16.

func (UUIDv7) Time

func (u UUIDv7) Time() time.Time

Timestamp returns unix epoch stored in the struct without millisecond precision

func (UUIDv7) Timestamp

func (u UUIDv7) Timestamp() uint64

Timestamp returns unix epoch stored in the struct without millisecond precision

func (UUIDv7) ToBinaryString

func (u UUIDv7) ToBinaryString() string

func (UUIDv7) ToBitArray

func (u UUIDv7) ToBitArray() []bool

func (UUIDv7) ToMicrosoftString

func (u UUIDv7) ToMicrosoftString() string

func (UUIDv7) ToString

func (u UUIDv7) ToString() string

func (UUIDv7) Var

func (u UUIDv7) Var() uint16

Var doing something described in the draft, but I don't know what

func (UUIDv7) Ver

func (u UUIDv7) Ver() uint16

Ver returns a version of UUID, 07 in this case

type UUIDv7Generator

type UUIDv7Generator struct {
	SubsecondPrecisionLength int

	NodePrecisionLength int
	Node                uint64

	CounterPrecisionLength int
	// contains filtered or unexported fields
}

Generator is a primary structure that allows you to create new UUIDv7 SubsecondPrecisionLength is a number of bits to carry sub-second information. On a systems with a high-resulution sub-second precision (like x64 Linux/Windows/MAC) it can go up to 48 bits NodePrecisionBits is a number of bits for node information. If this is not set to 0 [default], a Node variable must be set to a non-zero value Node information about the node generating UUIDs CounterPrecisionBits how many bits are dedicated to a counter. If two UUIDs were generated at the same time an internal counter would increase, distinguishing those UUIDs

func (*UUIDv7Generator) Next

func (u *UUIDv7Generator) Next() (uuid UUIDv7)

UUIDv7FromBytes creates a new UUIDv7 from a slice of bytes and returns an error, if an array length does not equal 16.

func (*UUIDv7Generator) Parse added in v0.2.1

func (u *UUIDv7Generator) Parse(id *UUIDv7) (precisionSeconds float64, counter uint64, node uint64)

Parse finds the values for precisionSeconds, counter and node for a specified UUID on a specified generator.

type UUIDv8

type UUIDv8 uuidBase

func UUIDv8FromBytes

func UUIDv8FromBytes(b []byte) (uuid UUIDv8, err error)

UUIDv8FromBytes creates a new UUIDv8 from a slice of bytes and returns an error, if an array length does not equal 16.

Jump to

Keyboard shortcuts

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