gouuidv6

package module
v0.0.0-...-99413e4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 10 Imported by: 4

README

"Version 6" UUIDs in Go

NOTE: This implementation is a prototype from a few years ago. There is an update proposal at https://tools.ietf.org/html/draft-peabody-dispatch-new-uuid-format and the outcome of that proposal will determine what happens with this project.

See https://bradleypeabody.github.io/uuidv6/ for an explanation of 'Version 6' UUIDs.

Documentation

Overview

Implements "Version 6" UUIDs in Go. See http://bradleypeabody.github.io/uuidv6/ UUIDs sort correctly by time when naively sorted as raw bytes, have a Time() function that returns time the UUID was created and have a reasonable guarantee of being globally unique (based on the specifications from RFC 4122, with a few intentional exceptions.)

Index

Constants

This section is empty.

Variables

View Source
var Base64UUIDAlphabet = `-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz`

Base64UUIDAlphabet uses the same characters as "url safe" base64, but puts them in ascii sequence so encoded data sorts the same as the raw bytes.

View Source
var Base64UUIDEncoding = base64.NewEncoding(Base64UUIDAlphabet).WithPadding(base64.NoPadding)

Base64UUIDEncoding is a base64.Encoding that has no padding and uses Base64UUIDAlphabet.

Functions

func RandomizeNode

func RandomizeNode()

Set the 'node' part of the UUID to a random value, instead of using one of the MAC addresses from the system. Use this if you are concerned about the privacy aspect of using a MAC address.

Types

type UUID

type UUID [16]byte

"Version 6" UUID.

func New

func New() UUID

Return a new UUID initialized to a proper value according to "Version 6" rules.

func NewFromTime

func NewFromTime(t time.Time) UUID

func Parse

func Parse(us string) (UUID, error)

Parse text representation

func (UUID) Bytes

func (u UUID) Bytes() []byte

Return as byte slice.

func (UUID) IsNil

func (u UUID) IsNil() bool

Return true if all UUID bytes are zero.

func (UUID) MarshalBinary

func (u UUID) MarshalBinary() ([]byte, error)

func (UUID) MarshalJSON

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

func (UUID) MarshalText

func (u UUID) MarshalText() ([]byte, error)

func (*UUID) Scan

func (u *UUID) Scan(value interface{}) error

func (UUID) String

func (u UUID) String() string

Textual representation per RFC 4122, e.g. "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"

func (UUID) Time

func (u UUID) Time() time.Time

Extract and return the time from the UUID.

func (*UUID) UnmarshalBinary

func (u *UUID) UnmarshalBinary(data []byte) error

func (*UUID) UnmarshalJSON

func (u *UUID) UnmarshalJSON(data []byte) error

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(text []byte) (err error)

func (UUID) Value

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

type UUIDB64

type UUIDB64 UUID

UUIDB64 is like UUID but encodes using a "base64 uuid" representation for it's string value (as well as in the database).

func NewB64

func NewB64() UUIDB64

func NewB64FromTime

func NewB64FromTime(t time.Time) UUIDB64

func ParseB64

func ParseB64(us string) (UUIDB64, error)

Parse base64 text representation

func (UUIDB64) Bytes

func (u UUIDB64) Bytes() []byte

Return as byte slice.

func (UUIDB64) IsNil

func (u UUIDB64) IsNil() bool

Return true if all UUIDB64 bytes are zero.

func (UUIDB64) MarshalBinary

func (u UUIDB64) MarshalBinary() ([]byte, error)

func (UUIDB64) MarshalJSON

func (u UUIDB64) MarshalJSON() ([]byte, error)

func (UUIDB64) MarshalText

func (u UUIDB64) MarshalText() ([]byte, error)

func (*UUIDB64) Scan

func (u *UUIDB64) Scan(value interface{}) error

func (UUIDB64) String

func (u UUIDB64) String() string

B64String returns the UUID encoded with Base64UUIDEncoding.

func (UUIDB64) Time

func (u UUIDB64) Time() time.Time

Extract and return the time from the UUIDB64.

func (*UUIDB64) UnmarshalBinary

func (u *UUIDB64) UnmarshalBinary(data []byte) error

func (*UUIDB64) UnmarshalJSON

func (u *UUIDB64) UnmarshalJSON(data []byte) error

func (*UUIDB64) UnmarshalText

func (u *UUIDB64) UnmarshalText(text []byte) (err error)

func (UUIDB64) Value

func (u UUIDB64) Value() (driver.Value, error)

type UUIDB64Slice

type UUIDB64Slice []UUIDB64

func (UUIDB64Slice) Len

func (s UUIDB64Slice) Len() int

func (UUIDB64Slice) Less

func (s UUIDB64Slice) Less(i, j int) bool

func (UUIDB64Slice) Swap

func (s UUIDB64Slice) Swap(i, j int)

type UUIDSlice

type UUIDSlice []UUID

Slice of UUIDs, sorts using first 64bits (where the time is)

func (UUIDSlice) Len

func (s UUIDSlice) Len() int

func (UUIDSlice) Less

func (s UUIDSlice) Less(i, j int) bool

FIXME: Not sure this is smart - why wouldn't we just sort by the entire binary value, to ensure consistency...

func (UUIDSlice) Swap

func (s UUIDSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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